From 2b034ffa10bc6d14adccec6cef5b3c587a70a283 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 26 Mar 2018 12:29:10 -0400 Subject: [PATCH] keypad driver progress --- include/keypad.h | 28 +++-------- initrd/graph | 67 ++++++++++++++++++++++++++ initrd/init | 69 ++------------------------- libinterp.a | Bin 47938 -> 71812 bytes src/keypad.c | 121 +++++++++++++++++++++++++++++++---------------- src/main.c | 24 +++++----- src/stdlib.c | 1 - 7 files changed, 169 insertions(+), 141 deletions(-) create mode 100644 initrd/graph diff --git a/include/keypad.h b/include/keypad.h index 2e5fa9c..3dbebdf 100644 --- a/include/keypad.h +++ b/include/keypad.h @@ -23,34 +23,18 @@ #include -#define K0 (uint16_t)(1 << 0) -#define K1 (uint16_t)(1 << 1) -#define K2 (uint16_t)(1 << 2) -#define K3 (uint16_t)(1 << 3) -#define K4 (uint16_t)(1 << 4) -#define K5 (uint16_t)(1 << 5) -#define K6 (uint16_t)(1 << 6) -#define K7 (uint16_t)(1 << 7) -#define K8 (uint16_t)(1 << 8) -#define K9 (uint16_t)(1 << 9) -#define KS (uint16_t)(1 << 10) -#define KP (uint16_t)(1 << 11) - /** - * Initializes GPIO for the keypad. Must be called before any keypad reading. + * Initializes GPIO for the keypad. + * Starts a task to poll the buttons. Must be called before any keypad reading. */ void keypad_init(void); /** - * Reads the state of the keypad and returns it. - * @return the keypad's state + * Reads the last pressed key on the keypad. + * This driver keeps an 8 key buffer for key presses. + * @return the pressed key (as the character it represents), zero if no presses */ -uint16_t keypad_get(void); +int keypad_get(void); -/** - * Tests if the given key is currently pressed, returning non-zero if it is. - * @return non-zero if pressed - */ -uint8_t keypad_isdown(uint16_t); #endif // KEYPAD_H_ diff --git a/initrd/graph b/initrd/graph new file mode 100644 index 0000000..a218474 --- /dev/null +++ b/initrd/graph @@ -0,0 +1,67 @@ +# graph area +plotx = 50 +ploty = 50 +plotw = 380 +ploth = 220 +cx = plotx + plotw / 2 +cy = ploty + ploth / 2 + +# graph range +xmin = 0 - 10 +xmax = 10 +ymin = 0 - 10 +ymax = 10 + +xinc = plotw / (xmax - xmin) +yinc = ploth / (ymax - ymin) + +mlines = color(3, 3, 3) + +func(makegrid) { + rect(plotx, ploty, plotw, ploth, 0) + + x = plotx + while (x <= plotx + plotw) { + line(x, ploty, x, ploty + ploth, mlines) + x = x + xinc + } + + y = ploty + while (y <= ploty + ploth) { + line(plotx, y, plotx + plotw, y, mlines) + y = y + yinc + } + + line(cx, ploty, cx, ploty + ploth, 32767) + line(plotx, cy, plotx + plotw, cy, 32767) +} + +# +# BIG LOOP - ask for equ, graph it +# + +makegrid +clearcmd = "clear" +while (1) { + rect(0, 0, 480, 40, 0) + print("f(x) = ") + Fx = gets() + + if (Fx == clearcmd) { + makegrid + } else { + # do function + x = xmin + while (x < xmax) { + y = solve(Fx) + y = 0 - y + if ((y >= ymin) & (y <= ymax)) { + pixel(cx + x * xinc, cy + y * yinc, 511) + } + x = x + 1 / xinc + } + } + + ppos(0, 0) +} + diff --git a/initrd/init b/initrd/init index a218474..17eb48d 100644 --- a/initrd/init +++ b/initrd/init @@ -1,67 +1,8 @@ -# graph area -plotx = 50 -ploty = 50 -plotw = 380 -ploth = 220 -cx = plotx + plotw / 2 -cy = ploty + ploth / 2 - -# graph range -xmin = 0 - 10 -xmax = 10 -ymin = 0 - 10 -ymax = 10 - -xinc = plotw / (xmax - xmin) -yinc = ploth / (ymax - ymin) - -mlines = color(3, 3, 3) - -func(makegrid) { - rect(plotx, ploty, plotw, ploth, 0) - - x = plotx - while (x <= plotx + plotw) { - line(x, ploty, x, ploty + ploth, mlines) - x = x + xinc - } - - y = ploty - while (y <= ploty + ploth) { - line(plotx, y, plotx + plotw, y, mlines) - y = y + yinc - } - - line(cx, ploty, cx, ploty + ploth, 32767) - line(plotx, cy, plotx + plotw, cy, 32767) -} - -# -# BIG LOOP - ask for equ, graph it -# - -makegrid -clearcmd = "clear" +input = 0 while (1) { - rect(0, 0, 480, 40, 0) - print("f(x) = ") - Fx = gets() - - if (Fx == clearcmd) { - makegrid - } else { - # do function - x = xmin - while (x < xmax) { - y = solve(Fx) - y = 0 - y - if ((y >= ymin) & (y <= ymax)) { - pixel(cx + x * xinc, cy + y * yinc, 511) - } - x = x + 1 / xinc - } + while (input == 0) { + input = getkey } - - ppos(0, 0) + print(input) + input = 0 } - diff --git a/libinterp.a b/libinterp.a index 123d9f418c141931bf4de8feec44f22e84b421e5..c135dfcada4726243988951d049d3826890b2386 100644 GIT binary patch delta 24139 zcmcJ1dwi6|)&D%t?q+YfY%Z_~+1+fegd~t~50F4Wh#=vjq7nr+Aqi{*Ld=C*lnn}s zcW^AWN|lOQyj2ToL21>ht*zRER_lef6l>eJwTjigqE!5Szw^xIVrk#^{o}Wv&ok$o znRCvZnP;B4p4lJ&x4Gr}_U*yg#PMUtPYQ=C!u$;k!{JGzC#cwPxWOZYm?MPkt^fRt zd{&76+Y|fu0?TTI`2YT#i%bqJ{P)jq4+(Lm=frLy&iw2T7zd45XIDqlsx@sb0!W*M zwX9hsTGn*oX%Wj?+nQV2nnmZz*7jwq8rxQi*7oksD8e=EDp)OASG06BcC3iQ2o$xp z^^YVkU7i?u z3T^~TqGto~!e1cX=eYubA7HFV;|rM&ES-Uk75fjSx}1B~vOJz|QtN%pOLz)UC(Z|R5RH0!mN`Fk z0i{@c=c9i|m|?fg1(SOyU*M3p5tHd2`2qE$GP<0oNQ$f!?h2~3d&VoJS{YNDb?FO`=~FHf*6-4PhRR7QMM0a zE_df#N+mJ1i>UArV+|S(zV*;KN z#Gii?wGsAoL$&)w;Y3Y(9-t8~6#y^xd?stWIWPMh*O-l19FWrZHwjBv5%b!KpUE$}6t$K_$~_}F16Dz>{TOZ3NpXRMca>jMzFO z_!Al%GoJzHQ8QRgC0opPl>L|)49XEnyT%=)c+fZ(;-UM%o#@Ur?gK+WeKPq97l8|@ zw!l#BAaJq#JgF%AR+ew7@kj8AfS379Q$#|bR!&YXie1g9dXv3?2>3}{tjxCuwo=(8 z=4U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)f;!9fk5Es8 zk!ZXAmHe_TG6}y?+9w-4uj%aoPcb@&^);w!s?j;FeP#8d5r%O_B}q2ENQ-$U$EBhs|t*Iv&a^gr`6ReE$etG%FC9@WOK z`$6lyo*IB|GKC0D8&-QgoXgYgC8XG4OHzWr131*!7}JJ!uVb1@3wjj z$~caSO&k8%>Z7FRqCxpxD=1%C(oB@eODC{8xo&ALC)e9ci|G|bEKBNxM=qPmb_5~* z6|a(Vn-*>Uaq z9MPZPG}8|b3ExX~Wfq$+`>)Jk$K*6>e<`<8`>K3zWh}8=Us+0R-l_z)R@SYG4LXbH z-9E0#86|SVs-A3;e0fzSy>NZJD%Qy{zTLOIjY@WhbgoWdV`RV8eb^N_arJ1nOCDG~ zihhccVof~zlT2R|%ZAI*YsRoNxpU0~c2$bC3Eav%GuJlR{++ip<420$Z{FHj|LYF= zeSPM{iL)D;Iy1I@7RBC_kq3<5CJt<4xzcuUF8$8aM(rv2{lR4Ro{T>f$1VB3H?`VB jPQpBX2ybUwsO=$-P+KlPr?yxIA5JvSqn9j-KO6Ed1}(F? diff --git a/src/keypad.c b/src/keypad.c index fad774a..06cef51 100644 --- a/src/keypad.c +++ b/src/keypad.c @@ -18,66 +18,105 @@ * along with this program. If not, see . */ +#include #include #include +#include -#define PIN_0 GPIO_PORT(B, 2) -#define PIN_1 GPIO_PORT(B, 1) -#define PIN_2 GPIO_PORT(A, 11) -#define PIN_3 GPIO_PORT(C, 8) -#define PIN_4 GPIO_PORT(B, 15) -#define PIN_5 GPIO_PORT(B, 12) -#define PIN_6 GPIO_PORT(C, 6) -#define PIN_7 GPIO_PORT(B, 14) -#define PIN_8 GPIO_PORT(B, 11) -#define PIN_9 GPIO_PORT(C, 5) -#define PIN_S GPIO_PORT(B, 13) -#define PIN_P GPIO_PORT(A, 12) +#define ROW_0 GPIO_PORT(B, 15) +#define ROW_1 GPIO_PORT(B, 14) +#define ROW_2 GPIO_PORT(B, 13) +#define ROW_3 GPIO_PORT(C, 4) +#define COL_0 GPIO_PORT(B, 1) +#define COL_1 GPIO_PORT(B, 2) +#define COL_2 GPIO_PORT(B, 11) +#define COL_3 GPIO_PORT(B, 12) +#define COL_4 GPIO_PORT(A, 11) + +#define ROWS 4 +#define COLS 5 typedef struct { GPIO_TypeDef *port; uint16_t pin; - uint16_t keycode; -} key_t; +} port_t; + +static const port_t keypad_rows[ROWS] = { + { ROW_0 }, { ROW_1 }, { ROW_2 }, { ROW_3 } +}; + +static const port_t keypad_cols[COLS] = { + { COL_0 }, { COL_1 }, { COL_2 }, { COL_3 }, { COL_4 } +}; -static const key_t keypad_map[12] = { - { PIN_0, K0 }, - { PIN_1, K1 }, - { PIN_2, K2 }, - { PIN_3, K3 }, - { PIN_4, K4 }, - { PIN_5, K5 }, - { PIN_6, K6 }, - { PIN_7, K7 }, - { PIN_8, K8 }, - { PIN_9, K9 }, - { PIN_S, KS }, - { PIN_P, KP } +static const int keypad_map[ROWS][COLS] = { + { '7', '8', '9', 'x', '/' }, + { '4', '5', '6', 'y', '*' }, + { '3', '2', '1', 'z', '-' }, + { '.', '0', '\b', '\n', '+' } }; +#define BUFFER_SIZE 8 +static char keypad_buffer = 'A';//[BUFFER_SIZE]; +//static int keypad_buffer_pos = -1; + +void keypad_task(void) +{ + unsigned int col = 0; + while (1) { + gpio_dout(keypad_cols[col].port, keypad_cols[col].pin, 1); + for (unsigned int row = 0; row < ROWS; row++) { + if (gpio_din(keypad_rows[row].port, keypad_rows[row].pin)) { + //if (keypad_buffer_pos < BUFFER_SIZE) + keypad_buffer/*[++keypad_buffer_pos]*/ = keypad_map[row][col]; + while (gpio_din(keypad_rows[row].port, keypad_rows[row].pin)) + delay(1); + break; + } + } + gpio_dout(keypad_cols[col].port, keypad_cols[col].pin, 0); + col++; + if (col == COLS) + col = 0; + + delay(10); + } +} + void keypad_init(void) { - for (uint8_t i = 0; i < 12; i++) { - GPIO_TypeDef *p = keypad_map[i].port; - uint16_t pin = keypad_map[i].pin; + for (uint8_t i = 0; i < ROWS; i++) { + GPIO_TypeDef *p = keypad_rows[i].port; + uint16_t pin = keypad_rows[i].pin; gpio_mode(p, pin, OUTPUT); + gpio_speed(p, pin, VERYHIGH); gpio_dout(p, pin, 0); gpio_mode(p, pin, INPUT); - //gpio_pupd(p, pin, PULLDOWN); + gpio_pupd(p, pin, PULLDOWN); } -} -uint16_t keypad_get(void) -{ - uint16_t state = 0; - for (uint8_t i = 0; i < 12; i++) { - if (gpio_din(keypad_map[i].port, keypad_map[i].pin)) - state |= keypad_map[i].keycode; + for (uint8_t i = 0; i < COLS; i++) { + GPIO_TypeDef *p = keypad_cols[i].port; + uint16_t pin = keypad_cols[i].pin; + gpio_mode(p, pin, OUTPUT); + gpio_speed(p, pin, VERYHIGH); + gpio_dout(p, pin, 0); } - return state; + + task_start(keypad_task, 1024); } -uint8_t keypad_isdown(uint16_t keycode) +int keypad_get(void) { - return (keypad_get() & keycode); + //if (keypad_buffer_pos < 0) + // return 0; + + //int key = keypad_buffer[0]; + //for (int i = keypad_buffer_pos - 1; i > 0; i--) + // keypad_buffer[i - 1] = keypad_buffer[i]; + //keypad_buffer_pos--; + //return key; + int ret = keypad_buffer; + keypad_buffer = 0; + return ret; } diff --git a/src/main.c b/src/main.c index 9844199..1e9b58d 100644 --- a/src/main.c +++ b/src/main.c @@ -18,22 +18,22 @@ * along with this program. If not, see . */ -#include #include -#include -#include -#include -#include #include #include +#include +#include +#include #include +#include +#include #include +#include +#include #include +#include #include -#include -#include -#include -#include +#include extern uint8_t __bss_end__; extern char *itoa(int, char *, int); @@ -54,12 +54,9 @@ int main(void) clock_init(); heap_init(&__bss_end__); gpio_init(); - keypad_init(); serial_init(); random_init(); - - //extern void keypad_init(void); - //keypad_init(); + keypad_init(); gpio_mode(GPIOA, 5, OUTPUT); @@ -77,6 +74,7 @@ void kmain(void) dsp_init(); dsp_rect(0, 0, LCD_WIDTH, LCD_HEIGHT, dsp_color(0, 0, 0)); dsp_cursoron(); + keypad_init(); task_start(task_interpreter, 4096); /*char buf[2]; diff --git a/src/stdlib.c b/src/stdlib.c index f5f9cc8..950f356 100644 --- a/src/stdlib.c +++ b/src/stdlib.c @@ -62,7 +62,6 @@ char *snprintf(char *buf, unsigned int max, const char *format, ...) break; case 'f': itoa((int)va_arg(args, double), nbuf, 10); - continue; break; default: buf[off++] = format[i];