1.1 --- a/bsp.c Sun May 19 22:06:40 2013 +0000
1.2 +++ b/bsp.c Tue May 21 15:08:07 2013 +0000
1.3 @@ -35,9 +35,8 @@
1.4 #include <time.h>
1.5 #include <stdio.h>
1.6 #include "bsp.h"
1.7 -#include "Display_Hardware_Driver.h"
1.8
1.9 -void bsp_init()
1.10 +void EPD_Pin_init()
1.11 {
1.12 OUT(UBB_DAT2);
1.13 OUT(UBB_DAT3);
1.14 @@ -45,230 +44,77 @@
1.15 OUT(UBB_CLK);
1.16 OUT(UBB_DAT0);
1.17 OUT(UBB_DAT1);
1.18 -}
1.19
1.20 -/* NanoNote-specific functions. */
1.21 -
1.22 -void shift_select()
1.23 -{
1.24 - CLR(MUX_S0);
1.25 -}
1.26 -
1.27 -void shift_update()
1.28 -{
1.29 - SET(SHIFT_RCK);
1.30 - CLR(SHIFT_RCK);
1.31 -}
1.32 -
1.33 -void shift_init()
1.34 -{
1.35 - /* Initiate a clear operation. */
1.36 -
1.37 - CLR(SHIFT_SCLR);
1.38 -
1.39 - /* Set clocks to known state. */
1.40 -
1.41 - CLR(SHIFT_SCK);
1.42 - CLR(SHIFT_RCK);
1.43 -
1.44 - /* Propagate the clear operation. */
1.45 -
1.46 - shift_update();
1.47 -
1.48 - /* Finalise the initialisation. */
1.49 -
1.50 - SET(SHIFT_SCLR);
1.51 + CLR(UBB_DAT2);
1.52 + CLR(UBB_DAT3);
1.53 + CLR(UBB_CMD);
1.54 + CLR(UBB_CLK);
1.55 + CLR(UBB_DAT0);
1.56 + CLR(UBB_DAT1);
1.57 }
1.58
1.59 -void shift_reinit()
1.60 +void EPD_Pin_EPD_CS(EPD_pinstate pin)
1.61 {
1.62 - /* Set clocks to known state. */
1.63 -
1.64 - CLR(SHIFT_SCK);
1.65 - CLR(SHIFT_RCK);
1.66 -
1.67 - /* Avoid clear operation. */
1.68 -
1.69 - SET(SHIFT_SCLR);
1.70 -}
1.71 -
1.72 -void shift_in(uint8_t v)
1.73 -{
1.74 - if (v)
1.75 - SET(SHIFT_SI);
1.76 + if (pin == HIGH)
1.77 + SET(EPD_SSEL);
1.78 else
1.79 - CLR(SHIFT_SI);
1.80 -
1.81 - SET(SHIFT_SCK);
1.82 - CLR(SHIFT_SCK);
1.83 + CLR(EPD_SSEL);
1.84 }
1.85
1.86 -void epd_select()
1.87 -{
1.88 - SET(MUX_S0);
1.89 -}
1.90 -
1.91 -/* Callback functions. */
1.92 -
1.93 -void bsp_InitDisplayHardware()
1.94 +void EPD_Pin_RESET(EPD_pinstate pin)
1.95 {
1.96 - /* This should do the following:
1.97 -
1.98 - PANEL = 0
1.99 - CS/SSEL = 0
1.100 - PWM = 0
1.101 - RESET = 0
1.102 - DIS = 0
1.103 -
1.104 - (Could shift 0, 0 -> PANEL, DIS
1.105 - or 0, 0, 0 -> PANEL, BORDER, DIS.)
1.106 - */
1.107 -
1.108 - shift_select();
1.109 - shift_init(); /* PANEL = DIS = 0 */
1.110 -
1.111 - epd_select();
1.112 - CLR(EPD_SSEL);
1.113 - CLR(EPD_PWM);
1.114 - CLR(EPD_RESET);
1.115 - CLR(EPD_MOSI);
1.116 -
1.117 - printf("Hardware initialised.\n");
1.118 + if (pin == HIGH)
1.119 + SET(EPD_RESET);
1.120 + else
1.121 + CLR(EPD_RESET);
1.122 + printf("RESET = %d\n", pin);
1.123 }
1.124
1.125 -void bsp_PowerOn()
1.126 +void EPD_Pin_PANEL_ON(EPD_pinstate pin)
1.127 {
1.128 - /* This should do the following:
1.129 -
1.130 - RESET = 0
1.131 - DIS = 0
1.132 - CS/SSEL = 0
1.133 - */
1.134 -
1.135 - epd_select();
1.136 - epd_rst_low();
1.137 -
1.138 - shift_select();
1.139 - shift_init(); /* PANEL = DIS = 0 */
1.140 -
1.141 - printf("RESET = PANEL = DIS = 0\n");
1.142 -
1.143 - /* Then, the following:
1.144 -
1.145 - PWM = 1/0 (5ms)
1.146 - PANEL = 1
1.147 - PWM = 1/0 (10ms)
1.148 - BORDER = 1?
1.149 - RESET = 1
1.150 - PWM = 1/0 (5ms)
1.151 - RESET = 0
1.152 - PWM = 1/0 (5ms)
1.153 - RESET = 1
1.154 - PWM = 1/0 (5ms)
1.155 + if (pin == HIGH)
1.156 + ubb_power(1);
1.157 + else
1.158 + ubb_power(0);
1.159 + printf("PANEL = %d\n", pin);
1.160 +}
1.161
1.162 - (Could shift 1 -> PANEL => PANEL=1, DIS=0
1.163 - or 1, 1 -> PANEL, BORDER => PANEL=1, BORDER=1, DIS=0)
1.164 - */
1.165 -
1.166 - epd_select();
1.167 - epd_spi_init();
1.168 - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks());
1.169 - epd_pwm_active(5);
1.170 - printf("PWM at 5ms done: %u\n", bsp_getMsTicks());
1.171 -
1.172 - shift_select();
1.173 - shift_init(); /* PANEL = DIS = 0 (still) */
1.174 - shift_in(1); /* PANEL = 1 */
1.175 - shift_update();
1.176 - printf("PANEL = 1\n");
1.177 -
1.178 - epd_select();
1.179 - printf("PWM at 10ms starting: %u\n", bsp_getMsTicks());
1.180 - epd_pwm_active(10);
1.181 - printf("PWM at 10ms done: %u\n", bsp_getMsTicks());
1.182 - epd_cs_high();
1.183 - epd_rst_high();
1.184 - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks());
1.185 - epd_pwm_active(5);
1.186 - printf("PWM at 5ms done: %u\n", bsp_getMsTicks());
1.187 - epd_rst_low();
1.188 - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks());
1.189 - epd_pwm_active(5);
1.190 - printf("PWM at 5ms done: %u\n", bsp_getMsTicks());
1.191 - epd_rst_high();
1.192 - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks());
1.193 - epd_pwm_active(5);
1.194 - printf("PWM at 5ms done: %u\n", bsp_getMsTicks());
1.195 -
1.196 - printf("Hardware powered.\n");
1.197 +void EPD_Pin_DISCHARGE(EPD_pinstate pin)
1.198 +{
1.199 + if (pin == HIGH)
1.200 + SET(EPD_DIS);
1.201 + else
1.202 + CLR(EPD_DIS);
1.203 + printf("DIS = %d\n", pin);
1.204 }
1.205
1.206 -void bsp_pwm_active(uint16_t delayInMs)
1.207 +void EPD_Pin_BORDER(EPD_pinstate pin)
1.208 {
1.209 - uint16_t numOfIterations;
1.210 +}
1.211
1.212 - numOfIterations = delayInMs * 100;
1.213 - for (; numOfIterations > 0; numOfIterations--)
1.214 - {
1.215 - // PWM_SET_HIGH;
1.216 +void EPD_Pin_PWM(EPD_pinstate pin)
1.217 +{
1.218 + if (pin == HIGH)
1.219 SET(EPD_PWM);
1.220 - bsp_delayUs(5); //100kHz (96kHz ideal)
1.221 - // PWM_SET_LOW;
1.222 + else
1.223 CLR(EPD_PWM);
1.224 - bsp_delayUs(5);
1.225 - }
1.226 }
1.227
1.228 -void bsp_Shutdown()
1.229 +EPD_pinstate epd_get_busy()
1.230 {
1.231 - /* This should complete the power off operation as follows:
1.232 -
1.233 - RESET = 0
1.234 - CS/SSEL = 0
1.235 - PANEL = 0
1.236 - BORDER = 0?
1.237 - DIS = 1
1.238 - DIS = 0 (after 150ms)
1.239 -
1.240 - (Could shift 0 -> PANEL => PANEL=0, DIS=1
1.241 - or 0, 0 -> PANEL, BORDER => PANEL=0, BORDER=0, DIS=1)
1.242 - */
1.243 -
1.244 - epd_select();
1.245 - epd_rst_low();
1.246 - epd_cs_low();
1.247 - epd_spi_detach();
1.248 -
1.249 - shift_reinit();
1.250 - shift_select();
1.251 - shift_in(0); /* PANEL = 0; DIS = 1 */
1.252 - shift_update();
1.253 - printf("Wait for 150ms, starting: %u\n", bsp_getMsTicks());
1.254 - epd_delay_ms(150);
1.255 - printf("Wait for 150ms, done: %u\n", bsp_getMsTicks());
1.256 - shift_in(0); /* PANEL = 0; DIS = 0 */
1.257 - shift_update();
1.258 -
1.259 - printf("Hardware shut down.\n");
1.260 + bsp_delayUs(1);
1.261 + return LOW;
1.262 }
1.263
1.264 -void bsp_spiInit()
1.265 +void bsp_spiWrite(uint8_t *buffer, uint16_t length)
1.266 {
1.267 - CLR(EPD_SCK);
1.268 -}
1.269 + uint8_t mask, *ptr, *limit = buffer + length;
1.270
1.271 -/**
1.272 - * Send the given value via MOSI.
1.273 - */
1.274 -void bsp_writeToDisplay(uint8_t *data, uint16_t len)
1.275 -{
1.276 - uint8_t mask, *ptr, *limit = data + len;
1.277 -
1.278 - for (ptr = data; ptr < limit; ptr++)
1.279 + for (ptr = buffer; ptr < limit; ptr++)
1.280 {
1.281 for (mask = 0x80; mask; mask >>= 1)
1.282 {
1.283 - if (*ptr & mask)
1.284 + if (*(ptr) & mask)
1.285 {
1.286 SET(EPD_MOSI);
1.287 }
1.288 @@ -290,15 +136,12 @@
1.289
1.290 void bsp_delayUs(uint32_t us)
1.291 {
1.292 - #ifndef NANONOTE
1.293 - struct timespec tv;
1.294 - tv.tv_sec = 0;
1.295 - tv.tv_nsec = us * 100;
1.296 - nanosleep(&tv, NULL);
1.297 - #else
1.298 - uint64_t i = us * 16;
1.299 - while (i-- > 0);
1.300 - #endif
1.301 + /* uint32_t now = bsp_getUsTicks(); */
1.302 +
1.303 + /* while (bsp_getUsTicks() - now < us); */
1.304 +
1.305 + uint32_t count = us * 24;
1.306 + while (count--);
1.307 }
1.308
1.309 uint32_t bsp_getMsTicks()
1.310 @@ -308,7 +151,12 @@
1.311 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
1.312 }
1.313
1.314 -/* Unsupported. */
1.315 +uint32_t bsp_getUsTicks()
1.316 +{
1.317 + struct timeval tv;
1.318 + gettimeofday(&tv, NULL);
1.319 + return tv.tv_sec * 1000000 + tv.tv_usec;
1.320 +}
1.321
1.322 int16_t bsp_getTemp()
1.323 {