1.1 --- a/EPD.c Sun May 19 22:06:40 2013 +0000
1.2 +++ b/EPD.c Tue May 21 15:08:07 2013 +0000
1.3 @@ -14,25 +14,14 @@
1.4
1.5
1.6 #include "EPD.h"
1.7 +#include "bsp.h"
1.8 +#include <stdio.h>
1.9
1.10 -typedef enum {
1.11 - LOW=0,
1.12 - HIGH=1
1.13 -} EPD_pinstate;
1.14 -
1.15 -static void EPD_line(uint16_t line, const uint8_t *data, uint8_t fixed_value, uint8_t read_progmem, EPD_stage stage);
1.16 +static void EPD_line(uint16_t line, const uint8_t *data, uint8_t fixed_value, EPD_stage stage);
1.17 static void SPI_send(const uint8_t *buffer, uint16_t length);
1.18 static void SPI_put(uint8_t c);
1.19 static void SPI_put_wait(uint8_t c);
1.20
1.21 -static void EPD_Pin_init();
1.22 -static void EPD_Pin_EPD_CS(EPD_pinstate pin);
1.23 -static void EPD_Pin_RESET(EPD_pinstate pin);
1.24 -static void EPD_Pin_PANEL_ON(EPD_pinstate pin);
1.25 -static void EPD_Pin_DISCHARGE(EPD_pinstate pin);
1.26 -static void EPD_Pin_BORDER(EPD_pinstate pin);
1.27 -static EPD_pinstate epd_get_busy(void);
1.28 -
1.29 static void epd_pwm_active(uint16_t delayInMs);
1.30
1.31
1.32 @@ -80,28 +69,18 @@
1.33 static void EPD_frame_fixed(uint8_t fixed_value, EPD_stage stage) {
1.34 uint8_t line;
1.35 for (line = 0; line < epd.lines_per_display ; ++line) {
1.36 - EPD_line(line, 0, fixed_value, FALSE, stage);
1.37 + EPD_line(line, 0, fixed_value, stage);
1.38 }
1.39 }
1.40
1.41 -static void EPD_frame_data(PROGMEM const uint8_t *image, EPD_stage stage){
1.42 +static void EPD_frame_data(const uint8_t *image, EPD_stage stage){
1.43 uint8_t line;
1.44 for (line = 0; line < epd.lines_per_display ; ++line) {
1.45 - EPD_line(line, &image[line * epd.bytes_per_line], 0, TRUE, stage);
1.46 + EPD_line(line, &image[line * epd.bytes_per_line], 0, stage);
1.47 }
1.48 }
1.49
1.50
1.51 -#if defined(EPD_ENABLE_EXTRA_SRAM)
1.52 -static void EPD_frame_sram(const uint8_t *image, EPD_stage stage){
1.53 - uint8_t line;
1.54 - for (line = 0; line < epd.lines_per_display ; ++line) {
1.55 - EPD_line(line, &image[line * epd.bytes_per_line], 0, FALSE, stage);
1.56 - }
1.57 -}
1.58 -#endif
1.59 -
1.60 -
1.61 static void EPD_frame_fixed_repeat(uint8_t fixed_value, EPD_stage stage) {
1.62 int32_t stage_time = epd.factored_stage_time;
1.63 do {
1.64 @@ -117,7 +96,7 @@
1.65 }
1.66
1.67
1.68 -static void EPD_frame_data_repeat(PROGMEM const uint8_t *image, EPD_stage stage) {
1.69 +static void EPD_frame_data_repeat(const uint8_t *image, EPD_stage stage) {
1.70 int32_t stage_time = epd.factored_stage_time;
1.71 do {
1.72 uint32_t t_start = bsp_getMsTicks();
1.73 @@ -131,51 +110,7 @@
1.74 } while (stage_time > 0);
1.75 }
1.76
1.77 -#include <limits.h>
1.78 -#if defined(EPD_ENABLE_EXTRA_SRAM)
1.79 -static void EPD_frame_sram_repeat(const uint8_t *image, EPD_stage stage) {
1.80 - int32_t stage_time = epd.factored_stage_time;
1.81 - do {
1.82 - uint32_t t_start = bsp_getMsTicks();
1.83 - EPD_frame_sram(image, stage);
1.84 - uint32_t t_end = bsp_getMsTicks();
1.85 - if (t_end > t_start) {
1.86 - stage_time -= t_end - t_start;
1.87 - } else {
1.88 - stage_time -= t_start - t_end + 1 + 0xffffffffU;
1.89 - }
1.90 - } while (stage_time > 0);
1.91 -}
1.92 -#endif
1.93 -
1.94 -#if 0
1.95 -typedef void EPD_reader(void *buffer, uint32_t address, uint16_t length);
1.96 -
1.97 -static void EPD_frame_cb(uint32_t address, EPD_reader *reader, EPD_stage stage) {
1.98 - static uint8_t buffer[264 / 8];
1.99 - uint8_t line;
1.100 - for (line = 0; line < epd.lines_per_display; ++line) {
1.101 - reader(buffer, address + line * epd.bytes_per_line, epd.bytes_per_line);
1.102 - EPD_line(line, buffer, 0, FALSE, stage);
1.103 - }
1.104 -}
1.105 -
1.106 -static void EPD_frame_cb_repeat(uint32_t address, EPD_reader *reader, EPD_stage stage) {
1.107 - int32_t stage_time = epd.factored_stage_time;
1.108 - do {
1.109 - uint32_t t_start = bsp_getMsTicks();
1.110 - EPD_frame_cb(address, reader, stage);
1.111 - uint32_t t_end = bsp_getMsTicks();
1.112 - if (t_end > t_start) {
1.113 - stage_time -= t_end - t_start;
1.114 - } else {
1.115 - stage_time -= t_start - t_end + 1 + 0xffffffffU;
1.116 - }
1.117 - } while (stage_time > 0);
1.118 -}
1.119 -#endif
1.120 -
1.121 -static void EPD_line(uint16_t line, const uint8_t *data, uint8_t fixed_value, uint8_t read_progmem, EPD_stage stage) {
1.122 +static void EPD_line(uint16_t line, const uint8_t *data, uint8_t fixed_value, EPD_stage stage) {
1.123 // charge pump voltage levels
1.124 bsp_delayUs(10);
1.125 SPI_send(CU8(0x70, 0x04), 2);
1.126 @@ -473,7 +408,7 @@
1.127 void EPD_end(void) {
1.128
1.129 EPD_frame_fixed(0x55, EPD_normal); // dummy frame
1.130 - EPD_line(0x7fffu, 0, 0x55, FALSE, EPD_normal); // dummy_line
1.131 + EPD_line(0x7fffu, 0, 0x55, EPD_normal); // dummy_line
1.132
1.133 bsp_delayMs(25);
1.134
1.135 @@ -576,32 +511,22 @@
1.136 EPD_frame_fixed_repeat(0xaa, EPD_normal);
1.137 }
1.138
1.139 -// assuming a clear (white) screen output an image (PROGMEM data)
1.140 -void EPD_image(PROGMEM const uint8_t *image) {
1.141 +// assuming a clear (white) screen output an image
1.142 +void EPD_image(const uint8_t *image) {
1.143 EPD_frame_fixed_repeat(0xaa, EPD_compensate);
1.144 EPD_frame_fixed_repeat(0xaa, EPD_white);
1.145 EPD_frame_data_repeat(image, EPD_inverse);
1.146 EPD_frame_data_repeat(image, EPD_normal);
1.147 }
1.148
1.149 -// change from old image to new image (PROGMEM data)
1.150 -void EPD_image_progmem(PROGMEM const uint8_t *old_image, PROGMEM const uint8_t *new_image) {
1.151 +// change from old image to new image
1.152 +void EPD_image_change(const uint8_t *old_image, const uint8_t *new_image) {
1.153 EPD_frame_data_repeat(old_image, EPD_compensate);
1.154 EPD_frame_data_repeat(old_image, EPD_white);
1.155 EPD_frame_data_repeat(new_image, EPD_inverse);
1.156 EPD_frame_data_repeat(new_image, EPD_normal);
1.157 }
1.158
1.159 -#if defined(EPD_ENABLE_EXTRA_SRAM)
1.160 -// change from old image to new image (SRAM version)
1.161 -void EPD_image_sram(const uint8_t *old_image, const uint8_t *new_image) {
1.162 - EPD_frame_sram_repeat(old_image, EPD_compensate);
1.163 - EPD_frame_sram_repeat(old_image, EPD_white);
1.164 - EPD_frame_sram_repeat(new_image, EPD_inverse);
1.165 - EPD_frame_sram_repeat(new_image, EPD_normal);
1.166 -}
1.167 -#endif
1.168 -
1.169
1.170 static void SPI_put(uint8_t c) {
1.171 uint8_t placeholder = c;
1.172 @@ -629,86 +554,20 @@
1.173 EPD_Pin_EPD_CS(HIGH);
1.174 }
1.175
1.176 -static void EPD_Pin_init()
1.177 -{
1.178 - bsp_pinDir(6, 1); // CS
1.179 - bsp_pinDir(7, 0); // Driver Busy
1.180 - bsp_pinDir(8, 1); // Border
1.181 - bsp_pinDir(11, 1); // Pwm
1.182 - bsp_pinDir(12, 1); // Reset
1.183 - bsp_pinDir(13, 1); // Panel On
1.184 - bsp_pinDir(14, 1); // Discharge
1.185 -}
1.186 -
1.187 -static void EPD_Pin_EPD_CS(EPD_pinstate pin)
1.188 -{
1.189 - if (HIGH == pin) {
1.190 - bsp_pinSet(6);
1.191 - }
1.192 - else {
1.193 - bsp_pinClr(6);
1.194 - }
1.195 -}
1.196 -
1.197 -static void EPD_Pin_RESET(EPD_pinstate pin)
1.198 -{
1.199 - if (HIGH == pin) {
1.200 - bsp_pinSet(12);
1.201 - }
1.202 - else {
1.203 - bsp_pinClr(12);
1.204 - }
1.205 -}
1.206 -
1.207 -static void EPD_Pin_PANEL_ON(EPD_pinstate pin)
1.208 -{
1.209 - if (HIGH == pin) {
1.210 - bsp_pinSet(13);
1.211 - }
1.212 - else {
1.213 - bsp_pinClr(13);
1.214 - }
1.215 -}
1.216 -
1.217 -static void EPD_Pin_DISCHARGE(EPD_pinstate pin)
1.218 -{
1.219 - if (HIGH == pin) {
1.220 - bsp_pinSet(14);
1.221 - }
1.222 - else {
1.223 - bsp_pinClr(14);
1.224 - }
1.225 -}
1.226 -
1.227 -static void EPD_Pin_BORDER(EPD_pinstate pin)
1.228 -{
1.229 - if (HIGH == pin) {
1.230 - bsp_pinSet(8);
1.231 - }
1.232 - else {
1.233 - bsp_pinClr(8);
1.234 - }
1.235 -}
1.236 -
1.237 -static EPD_pinstate epd_get_busy(void)
1.238 -{
1.239 - if (bsp_pinState(7))
1.240 - return HIGH;
1.241 - else
1.242 - return LOW;
1.243 -}
1.244 -
1.245 static void epd_pwm_active(uint16_t delayInMs)
1.246 {
1.247 uint16_t numOfIterations;
1.248 + uint32_t now = bsp_getMsTicks();
1.249
1.250 numOfIterations = delayInMs * 100;
1.251
1.252 for(; numOfIterations > 0; numOfIterations--)
1.253 {
1.254 - bsp_pinSet(11);
1.255 + EPD_Pin_PWM(HIGH);
1.256 bsp_delayUs(5); //100kHz
1.257 - bsp_pinClr(11);
1.258 + EPD_Pin_PWM(LOW);
1.259 bsp_delayUs(5);
1.260 }
1.261 +
1.262 + printf("PWM done for %dms.\n", bsp_getMsTicks() - now);
1.263 }