1.1 --- a/bsp.c Sun May 19 21:42:23 2013 +0000
1.2 +++ b/bsp.c Tue May 21 15:23:53 2013 +0000
1.3 @@ -45,216 +45,17 @@
1.4 OUT(UBB_CLK);
1.5 OUT(UBB_DAT0);
1.6 OUT(UBB_DAT1);
1.7 -}
1.8
1.9 -/* NanoNote-specific functions. */
1.10 -
1.11 -void shift_select()
1.12 -{
1.13 - CLR(MUX_S0);
1.14 -}
1.15 -
1.16 -void shift_update()
1.17 -{
1.18 - SET(SHIFT_RCK);
1.19 - CLR(SHIFT_RCK);
1.20 -}
1.21 -
1.22 -void shift_init()
1.23 -{
1.24 - /* Initiate a clear operation. */
1.25 -
1.26 - CLR(SHIFT_SCLR);
1.27 -
1.28 - /* Set clocks to known state. */
1.29 -
1.30 - CLR(SHIFT_SCK);
1.31 - CLR(SHIFT_RCK);
1.32 -
1.33 - /* Propagate the clear operation. */
1.34 -
1.35 - shift_update();
1.36 -
1.37 - /* Finalise the initialisation. */
1.38 -
1.39 - SET(SHIFT_SCLR);
1.40 -}
1.41 -
1.42 -void shift_reinit()
1.43 -{
1.44 - /* Set clocks to known state. */
1.45 -
1.46 - CLR(SHIFT_SCK);
1.47 - CLR(SHIFT_RCK);
1.48 -
1.49 - /* Avoid clear operation. */
1.50 -
1.51 - SET(SHIFT_SCLR);
1.52 -}
1.53 -
1.54 -void shift_in(uint8_t v)
1.55 -{
1.56 - if (v)
1.57 - SET(SHIFT_SI);
1.58 - else
1.59 - CLR(SHIFT_SI);
1.60 -
1.61 - SET(SHIFT_SCK);
1.62 - CLR(SHIFT_SCK);
1.63 -}
1.64 -
1.65 -void epd_select()
1.66 -{
1.67 - SET(MUX_S0);
1.68 -}
1.69 -
1.70 -/* Callback functions. */
1.71 -
1.72 -void bsp_InitDisplayHardware()
1.73 -{
1.74 - /* This should do the following:
1.75 -
1.76 - PANEL = 0
1.77 - CS/SSEL = 0
1.78 - PWM = 0
1.79 - RESET = 0
1.80 - DIS = 0
1.81 -
1.82 - (Could shift 0, 0 -> PANEL, DIS
1.83 - or 0, 0, 0 -> PANEL, BORDER, DIS.)
1.84 - */
1.85 -
1.86 - shift_select();
1.87 - shift_init(); /* PANEL = DIS = 0 */
1.88 -
1.89 - epd_select();
1.90 - CLR(EPD_SSEL);
1.91 - CLR(EPD_PWM);
1.92 - CLR(EPD_RESET);
1.93 - CLR(EPD_MOSI);
1.94 -
1.95 - printf("Hardware initialised.\n");
1.96 -}
1.97 -
1.98 -void bsp_PowerOn()
1.99 -{
1.100 - /* This should do the following:
1.101 -
1.102 - RESET = 0
1.103 - DIS = 0
1.104 - CS/SSEL = 0
1.105 - */
1.106 -
1.107 - epd_select();
1.108 - epd_rst_low();
1.109 -
1.110 - shift_select();
1.111 - shift_init(); /* PANEL = DIS = 0 */
1.112 -
1.113 - printf("RESET = PANEL = DIS = 0\n");
1.114 -
1.115 - /* Then, the following:
1.116 -
1.117 - PWM = 1/0 (5ms)
1.118 - PANEL = 1
1.119 - PWM = 1/0 (10ms)
1.120 - BORDER = 1?
1.121 - RESET = 1
1.122 - PWM = 1/0 (5ms)
1.123 - RESET = 0
1.124 - PWM = 1/0 (5ms)
1.125 - RESET = 1
1.126 - PWM = 1/0 (5ms)
1.127 -
1.128 - (Could shift 1 -> PANEL => PANEL=1, DIS=0
1.129 - or 1, 1 -> PANEL, BORDER => PANEL=1, BORDER=1, DIS=0)
1.130 - */
1.131 -
1.132 - epd_select();
1.133 - epd_spi_init();
1.134 - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks());
1.135 - epd_pwm_active(5);
1.136 - printf("PWM at 5ms done: %u\n", bsp_getMsTicks());
1.137 -
1.138 - shift_select();
1.139 - shift_init(); /* PANEL = DIS = 0 (still) */
1.140 - shift_in(1); /* PANEL = 1 */
1.141 - shift_update();
1.142 - printf("PANEL = 1\n");
1.143 -
1.144 - epd_select();
1.145 - printf("PWM at 10ms starting: %u\n", bsp_getMsTicks());
1.146 - epd_pwm_active(10);
1.147 - printf("PWM at 10ms done: %u\n", bsp_getMsTicks());
1.148 - epd_cs_high();
1.149 - epd_rst_high();
1.150 - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks());
1.151 - epd_pwm_active(5);
1.152 - printf("PWM at 5ms done: %u\n", bsp_getMsTicks());
1.153 - epd_rst_low();
1.154 - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks());
1.155 - epd_pwm_active(5);
1.156 - printf("PWM at 5ms done: %u\n", bsp_getMsTicks());
1.157 - epd_rst_high();
1.158 - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks());
1.159 - epd_pwm_active(5);
1.160 - printf("PWM at 5ms done: %u\n", bsp_getMsTicks());
1.161 -
1.162 - printf("Hardware powered.\n");
1.163 -}
1.164 -
1.165 -void bsp_pwm_active(uint16_t delayInMs)
1.166 -{
1.167 - uint16_t numOfIterations;
1.168 -
1.169 - numOfIterations = delayInMs * 100;
1.170 - for (; numOfIterations > 0; numOfIterations--)
1.171 - {
1.172 - // PWM_SET_HIGH;
1.173 - SET(EPD_PWM);
1.174 - bsp_delayUs(5); //100kHz (96kHz ideal)
1.175 - // PWM_SET_LOW;
1.176 - CLR(EPD_PWM);
1.177 - bsp_delayUs(5);
1.178 - }
1.179 -}
1.180 -
1.181 -void bsp_Shutdown()
1.182 -{
1.183 - /* This should complete the power off operation as follows:
1.184 -
1.185 - RESET = 0
1.186 - CS/SSEL = 0
1.187 - PANEL = 0
1.188 - BORDER = 0?
1.189 - DIS = 1
1.190 - DIS = 0 (after 150ms)
1.191 -
1.192 - (Could shift 0 -> PANEL => PANEL=0, DIS=1
1.193 - or 0, 0 -> PANEL, BORDER => PANEL=0, BORDER=0, DIS=1)
1.194 - */
1.195 -
1.196 - epd_select();
1.197 - epd_rst_low();
1.198 - epd_cs_low();
1.199 - epd_spi_detach();
1.200 -
1.201 - shift_reinit();
1.202 - shift_select();
1.203 - shift_in(0); /* PANEL = 0; DIS = 1 */
1.204 - shift_update();
1.205 - printf("Wait for 150ms, starting: %u\n", bsp_getMsTicks());
1.206 - epd_delay_ms(150);
1.207 - printf("Wait for 150ms, done: %u\n", bsp_getMsTicks());
1.208 - shift_in(0); /* PANEL = 0; DIS = 0 */
1.209 - shift_update();
1.210 -
1.211 - printf("Hardware shut down.\n");
1.212 + CLR(UBB_DAT2);
1.213 + CLR(UBB_DAT3);
1.214 + CLR(UBB_CMD);
1.215 + CLR(UBB_CLK);
1.216 + CLR(UBB_DAT0);
1.217 + CLR(UBB_DAT1);
1.218 }
1.219
1.220 void bsp_spiInit()
1.221 {
1.222 - CLR(EPD_SCK);
1.223 }
1.224
1.225 /**
1.226 @@ -296,8 +97,8 @@
1.227 tv.tv_nsec = us * 100;
1.228 nanosleep(&tv, NULL);
1.229 #else
1.230 - uint64_t i = us * 16;
1.231 - while (i-- > 0);
1.232 + uint64_t i = us * 24;
1.233 + while (i--);
1.234 #endif
1.235 }
1.236