aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/display_draw.h1
-rw-r--r--include/flash.h11
-rw-r--r--initrd/init38
-rw-r--r--initrd/init221
-rw-r--r--initrd/init31
-rw-r--r--libinterp.abin62136 -> 59924 bytes
-rw-r--r--src/display_draw.c15
-rw-r--r--src/flash.c95
-rw-r--r--src/initrd.c2
-rw-r--r--src/keypad.c.bak52
-rw-r--r--src/main.c25
-rw-r--r--src/script.c39
-rw-r--r--src/stdlib.c3
13 files changed, 267 insertions, 36 deletions
diff --git a/include/display_draw.h b/include/display_draw.h
index 5ed4224..823c697 100644
--- a/include/display_draw.h
+++ b/include/display_draw.h
@@ -5,6 +5,7 @@
void dsp_cursoron(void);
+void dsp_pixel(int x, int y, uint16_t color);
void dsp_line(int x, int y, int i, int j, uint16_t color);
void dsp_rect(int x, int y, int w, int h, uint16_t color);
diff --git a/include/flash.h b/include/flash.h
new file mode 100644
index 0000000..26fffd3
--- /dev/null
+++ b/include/flash.h
@@ -0,0 +1,11 @@
+#ifndef FLASH_H_
+#define FLASH_H_
+
+#include <stdint.h>
+
+void flash_init(void);
+
+void flash_read(char *buf, uint32_t addr, unsigned int count);
+void flash_write(const char *buf, uint32_t addr, unsigned int count);
+
+#endif // FLASH_H_
diff --git a/initrd/init b/initrd/init
index 4351743..56e5212 100644
--- a/initrd/init
+++ b/initrd/init
@@ -1 +1,37 @@
-print "Hello, world!"
+func Fx
+ ret (arg0 * arg0)
+end
+
+# graph area
+set plotx 0
+set ploty 0
+set plotw 479
+set ploth 319
+
+# graph range
+set xmin (0 - 10)
+set xmax 10
+set ymin (0 - 10)
+set ymax 10
+
+set xinc (plotw / (xmax - xmin))
+set yinc (ploth / (ymax - ymin))
+
+# print axis
+line 240 0 240 319 32767
+line 0 160 479 160 32767
+
+# do function
+set x xmin
+set cx (plotx + (plotw / 2))
+set cy (ploty + (ploth / 2))
+do
+ Fx x > y
+ set y (0 - y)
+ if ((y > ymin) & (y < ymax))
+ pixel (cx + (x * xinc)) (cy + (y * yinc)) 511
+ end
+ set x (x + (1 / xinc))
+while (x < xmax)
+
+print "Done."
diff --git a/initrd/init2 b/initrd/init2
new file mode 100644
index 0000000..47dbae1
--- /dev/null
+++ b/initrd/init2
@@ -0,0 +1,21 @@
+do
+ getkey > input
+ print input
+ delay 1000
+while (1)
+
+#do
+# getkey > input
+# if (input & 4)
+# rand 479 > x
+# rand 319 > y
+# rand 479 > i
+# rand 319 > j
+# rand 32767 > purple
+#
+# line x y i j purple
+# end
+#while (1)
+#
+#print "done"
+
diff --git a/initrd/init3 b/initrd/init3
new file mode 100644
index 0000000..4351743
--- /dev/null
+++ b/initrd/init3
@@ -0,0 +1 @@
+print "Hello, world!"
diff --git a/libinterp.a b/libinterp.a
index d52e280..a11013c 100644
--- a/libinterp.a
+++ b/libinterp.a
Binary files differ
diff --git a/src/display_draw.c b/src/display_draw.c
index a315bf7..62578e3 100644
--- a/src/display_draw.c
+++ b/src/display_draw.c
@@ -100,6 +100,15 @@ void dsp_rect(int x, int y, int w, int h, uint16_t color)
UNLOCK;
}
+void dsp_pixel(int x, int y, uint16_t color)
+{
+ LOCK;
+ dsp_set_addr(x, y, x, y);
+ dsp_write_data(color >> 8);
+ dsp_write_data(color & 0xFF);
+ UNLOCK;
+}
+
void dsp_line(int x, int y, int i, int j, uint16_t color)
{
int dx = i - x;
@@ -115,11 +124,7 @@ void dsp_line(int x, int y, int i, int j, uint16_t color)
int e2;
while (1) {
- LOCK;
- dsp_set_addr(x, y, x, y);
- dsp_write_data(color >> 8);
- dsp_write_data(color & 0xFF);
- UNLOCK;
+ dsp_pixel(x, y, color);
if (x == i && y == j)
break;
e2 = err;
diff --git a/src/flash.c b/src/flash.c
new file mode 100644
index 0000000..3027ec0
--- /dev/null
+++ b/src/flash.c
@@ -0,0 +1,95 @@
+#include <stm32l476xx.h>
+#include <gpio.h>
+#include <clock.h>
+
+#define READ 0x03
+#define WRITE 0x02
+#define WREN 0x06
+#define WRDS 0x04
+
+#define NSS GPIO_PORT(B, 12)
+#define SCK GPIO_PORT(B, 13)
+#define MISO GPIO_PORT(B, 14)
+#define MOSI GPIO_PORT(B, 15)
+
+void flash_xchg(char *byte, int count);
+
+void flash_init(void)
+{
+ gpio_mode(NSS, ALTERNATE);
+ gpio_mode(SCK, ALTERNATE);
+ gpio_mode(MISO, ALTERNATE);
+ gpio_mode(MOSI, ALTERNATE);
+ GPIOB->AFR[1] |= 0x55550000; // alt mode SPI2
+
+ // clock enable
+ RCC->APB1ENR1 |= RCC_APB1ENR1_SPI2EN;
+
+ SPI2->CR1 &= ~(SPI_CR1_BR_Msk);
+ SPI2->CR1 |= (3 << SPI_CR1_BR_Pos);
+ SPI2->CR1 |= SPI_CR1_SSM | SPI_CR1_SSI;
+ SPI2->CR1 |= SPI_CR1_MSTR;
+ SPI2->CR2 &= ~(SPI_CR2_DS_Msk);
+ SPI2->CR2 |= (7 << SPI_CR2_DS_Pos);
+ SPI2->CR2 |= SPI_CR2_SSOE;
+ SPI2->CR2 |= SPI_CR2_FRXTH;
+ SPI2->CR1 |= SPI_CR1_SPE;
+
+ char buf[3];
+ buf[0] = READ;
+ buf[1] = 0;
+ buf[2] = 0;
+ buf[3] = 0;
+ flash_xchg(buf, 4);
+}
+
+void flash_xchg(char *byte, int count)
+{
+ uint32_t status = 0, dummy;
+ SPI2->CR1 &= ~(SPI_CR1_SSI);
+ while (SPI2->SR & SPI_SR_BSY);
+ for (int i = 0; i < count; i++) {
+ SPI2->DR = byte[i];
+ do status = SPI2->SR;
+ while (status & SPI_SR_BSY);
+ // discard rx
+ while (status & SPI_SR_RXNE) {
+ dummy = SPI2->DR;
+ status = SPI2->SR;
+ }
+ }
+ do status = SPI2->SR;
+ while (status & SPI_SR_BSY);
+
+ while (1) {
+ SPI2->DR = 0;
+ do status = SPI2->SR;
+ while (status & SPI_SR_BSY);
+ // discard rx
+ while (status & SPI_SR_RXNE) {
+ dummy = SPI2->DR;
+ status = SPI2->SR;
+ }
+ }
+
+ SPI2->CR1 |= SPI_CR1_SSI;
+ (void)dummy;
+}
+
+void flash_read(char *buf, uint32_t addr, unsigned int count)
+{
+ (void)buf;
+ (void)addr;
+ (void)count;
+ if (buf == 0)
+ return;
+}
+
+void flash_write(const char *buf, uint32_t addr, unsigned int count)
+{
+ (void)buf;
+ (void)addr;
+ (void)count;
+ if (buf == 0)
+ return;
+}
diff --git a/src/initrd.c b/src/initrd.c
index e90f9f0..948811f 100644
--- a/src/initrd.c
+++ b/src/initrd.c
@@ -61,7 +61,7 @@ initrd_file *initrd_getfileptr(const char *name)
return file;
uint32_t size = initrd_getsize(file) + sizeof(initrd_file);
offset += size;
- file += size;
+ file = (initrd_file *)((uint8_t *)file + size + 1);
}
return 0;
diff --git a/src/keypad.c.bak b/src/keypad.c.bak
new file mode 100644
index 0000000..f25d46f
--- /dev/null
+++ b/src/keypad.c.bak
@@ -0,0 +1,52 @@
+#include <stm32l476xx.h>
+#include <gpio.h>
+
+#define ADDR 0x20
+
+#define CONTROL 0x41
+#define ADDRESS 0x12
+
+void keypad_init(void)
+{
+ // clock init
+ RCC->CCIPR &= ~(RCC_CCIPR_I2C1SEL_Msk);
+ RCC->CCIPR |= 2 << RCC_CCIPR_I2C1SEL_Pos;
+ RCC->APB1ENR1 |= RCC_APB1ENR1_I2C1EN;
+
+ // set times
+ // PRESC, SCLDEL, SDADEL, SCLH, SCLL
+ I2C1->TIMINGR = (0 << 28) | (2 << 20) | (0 << 16) | (2 << 8) | 4;
+
+ // gpio init
+ gpio_mode(GPIOB, 8, ALTERNATE);
+ gpio_mode(GPIOB, 9, ALTERNATE);
+ GPIOB->AFR[1] &= ~(0xFF);
+ GPIOB->AFR[1] |= 0x44;
+
+ // go go go
+ I2C1->CR1 |= I2C_CR1_PE;
+
+ I2C1->CR2 |= ADDR << 1;
+ //I2C1->CR2 |= I2C_CR2_RD_WRN;
+ I2C1->CR2 &= ~(I2C_CR2_NBYTES);
+ I2C1->CR2 |= 1 << I2C_CR2_NBYTES_Pos;
+ I2C1->CR2 |= I2C_CR2_RELOAD;
+ I2C1->CR2 |= I2C_CR2_START;
+
+ while (!(I2C1->ISR & I2C_ISR_TXE));
+
+ I2C1->TXDR = ADDRESS;
+
+ while (I2C1->ISR & I2C_ISR_BUSY);
+
+ I2C1->ICR |= 0x30;
+ I2C1->CR2 |= I2C_CR2_RD_WRN;
+ I2C1->CR2 |= I2C_CR2_RELOAD;
+ I2C1->CR2 |= I2C_CR2_START;
+
+ while (1) {
+ while (!(I2C1->ISR & I2C_ISR_RXNE));
+ uint32_t v = I2C1->RXDR;
+ (void)v;
+ }
+}
diff --git a/src/main.c b/src/main.c
index 74ae6b7..71ce68f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -13,6 +13,7 @@
#include <script.h>
#include <random.h>
#include <keypad.h>
+#include <flash.h>
extern uint8_t _ebss;
extern char *itoa(int, char *, int);
@@ -24,7 +25,7 @@ int main(void)
{
asm("cpsid i");
// disable cached writes for precise debug info
- //*((uint32_t *)0xE000E008) |= 2;
+ *((uint32_t *)0xE000E008) |= 2;
// prepare flash latency for 80MHz operation
FLASH->ACR &= ~(FLASH_ACR_LATENCY);
@@ -58,14 +59,24 @@ void kmain(void)
dsp_cursoron();
task_start(task_interpreter, 4096);
+ /*char buf[2];
+ flash_init();
+ buf[0] = 'A';
+ flash_write(buf, 0, 1);
+ buf[0] = 0;
+ flash_read(buf, 0x00000000, 1);
+ buf[0] += ' ';
+ buf[1] = '\0';
+ dsp_puts(buf);*/
+
while (1) {
- gpio_dout(GPIOA, 5,
- (keypad_isdown(K0)));
- delay(10);
- /*gpio_dout(GPIOA, 5, 1);
+ //gpio_dout(GPIOA, 5,
+ // (keypad_isdown(K0)));
+ //delay(10);
+ gpio_dout(GPIOA, 5, 1);
delay(250);
gpio_dout(GPIOA, 5, 0);
- delay(250);*/
+ delay(250);
}
}
@@ -77,7 +88,7 @@ void task_interpreter(void)
char *s = initrd_getfile("init");
if (s == 0) {
- dsp_puts("init not found");
+ dsp_puts("can't find init");
goto end;
}
diff --git a/src/script.c b/src/script.c
index 78165b0..c7b3614 100644
--- a/src/script.c
+++ b/src/script.c
@@ -19,6 +19,7 @@ int script_line(interpreter *it);
int script_color(interpreter *it);
int script_rand(interpreter *it);
int script_getkey(interpreter *it);
+int script_pixel(interpreter *it);
void script_loadlib(interpreter *it)
{
@@ -31,11 +32,12 @@ void script_loadlib(interpreter *it)
inew_cfunc(it, "color", script_color);
inew_cfunc(it, "rand", script_rand);
inew_cfunc(it, "getkey", script_getkey);
+ inew_cfunc(it, "pixel", script_pixel);
}
int script_puts(interpreter *it)
{
- char *s = igetarg_string(it, 0);
+ const char *s = igetarg_string(it, 0);
dsp_puts(s);
//dsp_puts("\n");
//asm("mov r0, %0; svc 2" :: "r" (s));
@@ -44,7 +46,8 @@ int script_puts(interpreter *it)
int script_gets(interpreter *it)
{
- char *s = malloc(64), c[2] = {0, 0};
+ char *s = malloc(64);
+ char c[2] = {0, 0};
uint16_t index = 0;
do {
@@ -57,7 +60,7 @@ int script_gets(interpreter *it)
variable *v = igetarg(it, 0);
v->valtype = STRING;
- v->svalue = s;
+ v->value.p = (uint32_t)s;
return 0;
}
@@ -98,39 +101,33 @@ int script_color(interpreter *it)
{
uint16_t c = dsp_color(igetarg_integer(it, 0), igetarg_integer(it, 1),
igetarg_integer(it, 2));
- variable v;
- v.valtype = INTEGER;
- INT(&v) = c;
- v.svalue = 0;
- isetstr(&v);
- iret(it, &v);
+ variable *v = make_varn(0, (float)c);
+ iret(it, v);
+ free(v);
return 0;
}
int script_rand(interpreter *it)
{
- variable *v = (variable *)malloc(sizeof(variable));
unsigned int mod = igetarg_integer(it, 0);
unsigned int val = random_get();
- v->valtype = INTEGER;
- INT(v) = val % mod;
- v->svalue = 0;
- isetstr(v);
+ variable *v = make_varn(0, (float)(mod % val));
iret(it, v);
- free(v->svalue);
free(v);
return 0;
}
int script_getkey(interpreter *it)
{
- variable *v = (variable *)malloc(sizeof(variable));
- v->valtype = INTEGER;
- INT(v) = keypad_get();
- v->svalue = 0;
- isetstr(v);
+ variable *v = make_varn(0, (float)keypad_get());
iret(it, v);
- free(v->svalue);
free(v);
return 0;
}
+
+int script_pixel(interpreter *it)
+{
+ dsp_pixel(igetarg_integer(it, 0), igetarg_integer(it, 1),
+ igetarg_integer(it, 2));
+ return 0;
+}
diff --git a/src/stdlib.c b/src/stdlib.c
index 303db4d..ec67ff3 100644
--- a/src/stdlib.c
+++ b/src/stdlib.c
@@ -40,6 +40,7 @@ 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];
@@ -47,7 +48,7 @@ char *snprintf(char *buf, unsigned int max, const char *format, ...)
break;
}
if (nbuf[0] != '\0') {
- for (unsigned int j = 0; off < max &&
+ for (unsigned int j = 0; off < max && j < 32 &&
nbuf[j] != '\0'; off++, j++)
buf[off] = nbuf[j];
}