]> code.bitgloo.com Git - clyne/calculator.git/commitdiff
new initrd format work, bigger keypad
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 30 Mar 2018 01:26:53 +0000 (21:26 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 30 Mar 2018 01:26:53 +0000 (21:26 -0400)
Makefile
boot [new file with mode: 0644]
include/script.h
initrd.c [new file with mode: 0644]
initrd/calc [deleted file]
initrd/init
rba [new file with mode: 0755]
src/keypad.c
src/main.c
src/script.c

index 0b9e19ab7394e9f028f64105f8c60e783943a291..9620aa46bdff0c6cc61b5f2f4bedf031efad557c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ STRIP = strip
 MCUFLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
 AFLAGS = $(MCUFLAGS) 
 CFLAGS = $(MCUFLAGS) -ggdb \
-       -Iinclude -Iinclude/it -Iinclude/cmsis \
+       -Iinclude -Iinclude/cmsis \
        -fno-builtin -fsigned-char -ffreestanding \
        -Wall -Werror -Wextra -pedantic \
        -Wno-overlength-strings -Wno-discarded-qualifiers
diff --git a/boot b/boot
new file mode 100644 (file)
index 0000000..13e5876
--- /dev/null
+++ b/boot
@@ -0,0 +1,3 @@
+choice = filemenu
+print("\nChoice: ")
+print(choice)
index 971cccf30b8b7c8cdc9e77da342ce0b439f0b101..bddb8723e3075026708edddb932442019bfd0ee4 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef SCRIPT_H_
 #define SCRIPT_H_
 
-#include <parser.h>
+#include <it/parser.h>
 
 /**
  * Loads the library for the given interpreter instance.
diff --git a/initrd.c b/initrd.c
new file mode 100644 (file)
index 0000000..3f36cd9
--- /dev/null
+++ b/initrd.c
@@ -0,0 +1,42 @@
+#include <stdint.h>
+#include <string.h>
+
+extern uint8_t *initrd_start;
+extern uint32_t initrd_size;
+
+char *getfile(uint32_t offset)
+{
+       char *ptr = initrd_start;
+       for (uint32_t i = 0; i < offset; i++) {
+               uint32_t len = *((uint32_t *)ptr);
+               uint32_t datalen = *((uint32_t *)(ptr + 4 + len));
+               ptr += len + datalen + 8;
+               if (ptr >= (char *)(initrd_start + initrd_size))
+                       return 0;
+       }
+
+       return ptr;
+}
+
+char *readfile(const char *name)
+{
+       char *ptr;
+       for (uint32_t i = 0; ptr = getfile(i), ptr != 0; i++) {
+               uint32_t len = *((uint32_t *)ptr);
+               if (!strncmp(name, ptr + 4, len))
+                       return ptr + len + 8;
+       }
+       return 0;
+}
+
+uint32_t filesize(const char *name)
+{
+       char *ptr;
+       for (uint32_t i = 0; ptr = getfile(i), ptr != 0; i++) {
+               uint32_t len = *((uint32_t *)ptr);
+               if (!strncmp(name, ptr + 4, len))
+                       return *((uint32_t *)ptr + len + 4);
+       }
+       return 0;
+}
+
diff --git a/initrd/calc b/initrd/calc
deleted file mode 100644 (file)
index 7359f16..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-while (1) {
-       print("> ")
-       input = gets()
-       answer = solve(input)
-       print("\n")
-       print(answer)
-       print("\n")
-}
index 13e5876c7db5a7c708150d08dbbca8cb4ca8955f..7359f164cbabae0af6d6b4c636d11bafe753f7bf 100644 (file)
@@ -1,3 +1,8 @@
-choice = filemenu
-print("\nChoice: ")
-print(choice)
+while (1) {
+       print("> ")
+       input = gets()
+       answer = solve(input)
+       print("\n")
+       print(answer)
+       print("\n")
+}
diff --git a/rba b/rba
new file mode 100755 (executable)
index 0000000..52f37cb
Binary files /dev/null and b/rba differ
index f76271c3722d596812f7faa092836ecbcff81e30..5fe25379f27e3c04ab6c2b51daa14f158fd9a4e6 100644 (file)
 #include <gpio.h>
 #include <task.h>
 
-#define ROW_0 GPIO_PORT(A, 12)
-#define ROW_1 GPIO_PORT(B, 12)
-#define ROW_2 GPIO_PORT(B, 11)
-#define ROW_3 GPIO_PORT(C, 4)
-#define COL_0 GPIO_PORT(B, 13)
-#define COL_1 GPIO_PORT(B, 14)
-#define COL_2 GPIO_PORT(B, 15)
-#define COL_3 GPIO_PORT(B, 1)
-#define COL_4 GPIO_PORT(B, 2)
+#define ROW_0 GPIO_PORT(B, 2)
+#define ROW_1 GPIO_PORT(B, 1)
+#define ROW_2 GPIO_PORT(B, 15)
+#define ROW_3 GPIO_PORT(B, 14)
+#define ROW_4 GPIO_PORT(B, 13)
+#define ROW_5 GPIO_PORT(C, 4)
+#define COL_0 GPIO_PORT(B, 11)
+#define COL_1 GPIO_PORT(B, 12)
+#define COL_2 GPIO_PORT(A, 11)
+#define COL_3 GPIO_PORT(A, 12)
+#define COL_4 GPIO_PORT(C, 5)
 
-#define ROWS 4
+#define ROWS 6
 #define COLS 5
 
 typedef struct {
@@ -42,17 +44,21 @@ typedef struct {
 } port_t;
 
 static const port_t keypad_rows[ROWS] = {
-       { ROW_0 }, { ROW_1 }, { ROW_2 }, { ROW_3 }
+       { ROW_0 }, { ROW_1 }, { ROW_2 },
+       { ROW_3 }, { ROW_4 }, { ROW_5 }
 };
 
 static const port_t keypad_cols[COLS] = {
-       { COL_0 }, { COL_1 }, { COL_2 }, { COL_3 }, { COL_4 }
+       { COL_0 }, { COL_1 }, { COL_2 },
+       { COL_3 }, { COL_4 }
 };
 
 static const int keypad_map[ROWS][COLS] = {
-       { '7', '8', '9',  'x',  '/' },
-       { '4', '5', '6',  'y',  '*' },
-       { '1', '2', '3',  '=',  '-' },
+       { '&', '|', '^',  ' ',  ' ' },
+       { 'x', 'y', 'z',  '=',  ' ' },
+       { '7', '8', '9',  '(',  ')' },
+       { '4', '5', '6',  '/',  '%' },
+       { '1', '2', '3',  '*',  '-' },
        { '.', '0', '\b', '\n', '+' }
 };
 
index c9d37896648a1b545ac57ebbbf7fb4b6fdfa2691..d21407a18189c9bf06350c6211e51687ab5b53ba 100644 (file)
@@ -27,7 +27,7 @@
 #include <initrd.h>\r
 #include <keypad.h>\r
 #include <lcd.h>\r
-#include <parser.h>\r
+#include <it/parser.h>\r
 #include <random.h>\r
 #include <script.h>\r
 #include <serial.h>\r
index 518edc55e2e04652d47eb080980cb5a82d731ccc..049608b999b96aa03d524b13d43cc2f989c5bb1d 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <script.h>
 
-#include <builtins.h>
+#include <it/builtins.h>
 #include <clock.h>
 #include <display.h>
 #include <display_draw.h>
 #include <random.h>
 #include <serial.h>
 #include <stdlib.h>
+#include <it/string.h>
 #include <keypad.h>
 
-#include <string.h>
-
 #define igetarg_integer(it, n) ((int)igetarg(it, n)->value.f)
 
 int script_puts(instance *it);