diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clock.c | 20 | ||||
-rw-r--r-- | src/display.c | 20 | ||||
-rw-r--r-- | src/display_draw.c | 21 | ||||
-rw-r--r-- | src/flash.c | 20 | ||||
-rw-r--r-- | src/flash.c.bak | 110 | ||||
-rw-r--r-- | src/gpio.c | 20 | ||||
-rw-r--r-- | src/heap.c | 20 | ||||
-rw-r--r-- | src/initrd.c | 23 | ||||
-rw-r--r-- | src/keypad.c | 20 | ||||
-rw-r--r-- | src/keypad.c.bak | 20 | ||||
-rw-r--r-- | src/lcd.c.bak | 20 | ||||
-rw-r--r-- | src/main.c | 24 | ||||
-rw-r--r-- | src/random.c | 20 | ||||
-rw-r--r-- | src/script.c | 52 | ||||
-rw-r--r-- | src/serial.c | 20 | ||||
-rw-r--r-- | src/startup_stm32l476xx.s | 10 | ||||
-rw-r--r-- | src/stdlib.c | 22 | ||||
-rw-r--r-- | src/task.c | 20 |
18 files changed, 469 insertions, 13 deletions
diff --git a/src/clock.c b/src/clock.c index 0c8ca7c..284573c 100644 --- a/src/clock.c +++ b/src/clock.c @@ -1,3 +1,23 @@ +/** + * @file clock.c + * Basic clock utilities + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <clock.h> #include <stm32l476xx.h> diff --git a/src/display.c b/src/display.c index 163a742..e961299 100644 --- a/src/display.c +++ b/src/display.c @@ -1,3 +1,23 @@ +/* + * @file display.c + * Display library for ILI9481 display + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <display.h> #include <clock.h> diff --git a/src/display_draw.c b/src/display_draw.c index f58dda7..269f76c 100644 --- a/src/display_draw.c +++ b/src/display_draw.c @@ -1,3 +1,23 @@ +/** + * @file display_draw.c + * Provides functions for drawing to the display + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <display_draw.h> #include <display.h> #include <task.h> @@ -41,6 +61,7 @@ void dsp_putchar(int c) dsp_rect(0, 0, LCD_WIDTH, LCD_HEIGHT, 0); cury = 0; } + UNLOCK; return; } else if (c == '\b') { if (curx > 0) diff --git a/src/flash.c b/src/flash.c index 6b3ee00..e3de420 100644 --- a/src/flash.c +++ b/src/flash.c @@ -1,3 +1,23 @@ +/** + * @file flash.c + * Provides functionality for using an external SPI flash + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <stm32l476xx.h> #include <gpio.h> #include <clock.h> diff --git a/src/flash.c.bak b/src/flash.c.bak new file mode 100644 index 0000000..037eeae --- /dev/null +++ b/src/flash.c.bak @@ -0,0 +1,110 @@ +#include <stm32l476xx.h> +#include <gpio.h> +#include <clock.h> + +#define READ 0x03 +#define WRITE 0x02 +#define WREN 0x06 +#define WRDS 0x04 + +#define SCK GPIO_PORT(C, 9) +#define SI GPIO_PORT(B, 8) +#define SO GPIO_PORT(B, 9) +#define CS GPIO_PORT(C, 4) + +void flash_out(uint8_t); +uint8_t flash_in(void); + +void flash_init(void) +{ + gpio_mode(SCK, OUTPUT); + gpio_mode(SI, OUTPUT); + gpio_mode(CS, OUTPUT); + gpio_mode(SO, OUTPUT); + gpio_dout(SO, 0); + gpio_mode(SO, INPUT); + gpio_dout(CS, 1); + gpio_dout(SCK, 0); + gpio_dout(SI, 0); + + //RCC->AHB3ENR |= RCC_AHB3ENR_QSPIEN; + + //// 10MHz operation, per datasheet + //QUADSPI->CR &= ~(0xFF << QUADSPI_CR_PRESCALER_Pos); + //QUADSPI->CR |= 7 << QUADSPI_CR_PRESCALER_Pos; + + //// pick FSEL! 0=1, 1=2 + + //// FSIZE = 16, 2^17 bits = 1Mb + //QUADSPI->DCR = (16 << QUADSPI_DCR_FSIZE_Pos); + + //// Memmap mode, single-spi + //QUADSPI->CCR = (3 << QUADSPI_CCR_FMODE_Pos) | (1 << QUADSPI_CCR_DMODE_Pos) + // | (2 << QUADSPI_CCR_ADSIZE_Pos) | (1 << QUADSPI_CCR_ADMODE_Pos) + // | (1 << QUADSPI_CCR_IMODE_Pos); + //// TODO CCR also takes instruction byte + //QUADSPI->CCR |= (READ << QUADSPI_CCR_INSTRUCTION_Pos); + + //QUADSPI->CR |= QUADSPI_CR_EN; +} + +void flash_out(uint8_t byte) +{ + for (uint8_t i = 0; i < 8; i++) { + gpio_dout(SI, (byte & (1 << (7 - i)))); + gpio_dout(SCK, 1); + gpio_dout(SCK, 0); + } +} + +void flash_addr(uint32_t addr) +{ + for (uint8_t i = 0; i < 24; i++) { + gpio_dout(SI, (addr & (1 << (23 - i)))); + gpio_dout(SCK, 1); + gpio_dout(SCK, 0); + } +} + +uint8_t flash_in(void) +{ + uint8_t byte = 0; + for (uint8_t i = 0; i < 8; i++) { + gpio_dout(SCK, 1); + gpio_dout(SCK, 0); + if (gpio_din(SO)) + byte |= (1 << (7 - i)); + } + return byte; +} + +void flash_read(char *buf, uint32_t addr, unsigned int count) +{ + if (buf == 0) + return; + gpio_dout(CS, 0); + flash_out(READ); + flash_addr(addr); + for (unsigned int i = 0; i < count; i++) + buf[i] = flash_in(); + gpio_dout(CS, 1); +} + +void flash_write(const char *buf, uint32_t addr, unsigned int count) +{ + if (buf == 0) + return; + gpio_dout(CS, 0); + flash_out(WREN); + gpio_dout(CS, 1); + gpio_dout(CS, 0); + flash_out(WRITE); + flash_addr(addr); + for (unsigned int i = 0; i < count; i++) + flash_out(buf[i]); + gpio_dout(CS, 1); + delay(100); + //gpio_dout(CS, 0); + //flash_out(WRDS); + //gpio_dout(CS, 1); +} @@ -1,3 +1,23 @@ +/** + * @file gpio.c + * Abstracts gpio access, makes things easier + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <gpio.h> void gpio_init(void) @@ -1,3 +1,23 @@ +/** + * @file heap.c + * A basic memory manager + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <heap.h> #define HEAP_ALIGN 4 diff --git a/src/initrd.c b/src/initrd.c index 948811f..37e3764 100644 --- a/src/initrd.c +++ b/src/initrd.c @@ -1,3 +1,26 @@ +/** + * @file initrd.c + * Initrd image support + * An archive file (made with ar) can be linked into the final executable to + * allow files to be loaded in memory on boot. See mkinitrd.sh or the Makefile + * for more info. + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <initrd.h> extern uint8_t _binary_initrd_img_start[]; diff --git a/src/keypad.c b/src/keypad.c index 06e0b6a..fad774a 100644 --- a/src/keypad.c +++ b/src/keypad.c @@ -1,3 +1,23 @@ +/** + * @file keypad.c + * Manages the GPIO keypad + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <keypad.h> #include <gpio.h> diff --git a/src/keypad.c.bak b/src/keypad.c.bak index f25d46f..2fbefff 100644 --- a/src/keypad.c.bak +++ b/src/keypad.c.bak @@ -1,3 +1,23 @@ +/** + * @file keypad.c + * Manages the GPIO keypad using IO expanders + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <stm32l476xx.h> #include <gpio.h> diff --git a/src/lcd.c.bak b/src/lcd.c.bak index a2a8ca7..8229041 100644 --- a/src/lcd.c.bak +++ b/src/lcd.c.bak @@ -1,3 +1,23 @@ +/** + * @file lcd.c + * A basic library for writing a 16x2 text LCD. + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <lcd.h> #include <clock.h> #include <gpio.h> @@ -1,3 +1,23 @@ +/**
+ * @file main.c
+ * Entry point for operating system
+ *
+ * Copyright (C) 2018 Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#include <stm32l476xx.h>
#include <clock.h>
#include <heap.h>
@@ -15,7 +35,7 @@ #include <keypad.h>
#include <flash.h>
-extern uint8_t _ebss;
+extern uint8_t __bss_end__;
extern char *itoa(int, char *, int);
void kmain(void);
@@ -32,7 +52,7 @@ int main(void) FLASH->ACR |= FLASH_ACR_LATENCY_4WS;
clock_init();
- heap_init(&_ebss);
+ heap_init(&__bss_end__);
gpio_init();
keypad_init();
serial_init();
diff --git a/src/random.c b/src/random.c index 9c1e0d1..002b862 100644 --- a/src/random.c +++ b/src/random.c @@ -1,3 +1,23 @@ +/** + * @file random.c + * Provides true random number generation functionality + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <random.h> #include <stm32l476xx.h> diff --git a/src/script.c b/src/script.c index b69b023..be0fa37 100644 --- a/src/script.c +++ b/src/script.c @@ -1,3 +1,23 @@ +/** + * @file script.c + * Provides script library for using calculator hardware + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <script.h> #include <builtins.h> @@ -24,19 +44,41 @@ int script_color(instance *it); int script_rand(instance *it); int script_getkey(instance *it); int script_pixel(instance *it); +int script_menu(instance *it); void script_loadlib(instance *it) { inew_cfunc(it, "print", script_puts); inew_cfunc(it, "gets", script_gets); - inew_cfunc(it, "delay", script_delay); - inew_cfunc(it, "rect", script_rect); + inew_cfunc(it, "getkey", script_getkey); inew_cfunc(it, "ppos", script_ppos); + + inew_cfunc(it, "pixel", script_pixel); inew_cfunc(it, "line", script_line); + inew_cfunc(it, "rect", script_rect); inew_cfunc(it, "color", script_color); + inew_cfunc(it, "rand", script_rand); - inew_cfunc(it, "getkey", script_getkey); - inew_cfunc(it, "pixel", script_pixel); + inew_cfunc(it, "delay", script_delay); + + inew_cfunc(it, "menu", script_menu); +} + +int script_menu(instance *it) +{ + char listbuf[4]; + int nargs = igetarg_integer(it, 0); + float *resps = (float *)calloc(nargs, sizeof(float)); + strncpy(listbuf, " : \0", 4); + for (int i = 0; i < nargs; i++) { + listbuf[0] = i + '0'; + dsp_puts(listbuf); + dsp_puts((char *)igetarg(it, 1 + i * 2)->value.p); + dsp_puts("\n"); + resps[i] = igetarg(it, 2 + i * 2)->value.f; + } + free(resps); + return 0; } int script_puts(instance *it) @@ -125,7 +167,7 @@ int script_rand(instance *it) { unsigned int mod = igetarg_integer(it, 0); unsigned int val = random_get(); - variable *v = make_varf(0, (float)(mod % val)); + variable *v = make_varf(0, (float)(val % mod)); ipush(it, (uint32_t)v); return 0; } diff --git a/src/serial.c b/src/serial.c index de28275..31c7744 100644 --- a/src/serial.c +++ b/src/serial.c @@ -1,3 +1,23 @@ +/** + * @file serial.c + * Provides basic serial IO (through STM debug stuff) + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <stm32l476xx.h> #include <gpio.h> #include <clock.h> diff --git a/src/startup_stm32l476xx.s b/src/startup_stm32l476xx.s index f7e18a4..b26ced5 100644 --- a/src/startup_stm32l476xx.s +++ b/src/startup_stm32l476xx.s @@ -57,10 +57,8 @@ defined in linker script */ .word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
-/* start address for the .bss section. defined in linker script */
-.word _sbss
-/* end address for the .bss section. defined in linker script */
-.word _ebss
+
+.equ _estack, 0x20018000
.equ BootRAM, 0xF1E0F85F
/**
@@ -94,7 +92,7 @@ LoopCopyDataInit: adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
- ldr r2, =_sbss
+ ldr r2, =__bss_start__
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
@@ -102,7 +100,7 @@ FillZerobss: str r3, [r2], #4
LoopFillZerobss:
- ldr r3, = _ebss
+ ldr r3, = __bss_end__
cmp r2, r3
bcc FillZerobss
diff --git a/src/stdlib.c b/src/stdlib.c index e34d2a0..f5f9cc8 100644 --- a/src/stdlib.c +++ b/src/stdlib.c @@ -1,3 +1,25 @@ +/** + * @file stdlib.c + * Provides missing C standard library functions + * The newlib versions of these calls are not being used due to dependence on + * unsupported system calls. + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <stdlib.h> #include <ctype.h> @@ -1,3 +1,23 @@ +/** + * @file task.c + * Provides multitasking functionality + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <task.h> #include <heap.h> #include <stm32l476xx.h> |