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);
--- /dev/null
+#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_
-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."
--- /dev/null
+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"
+
--- /dev/null
+print "Hello, world!"
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;
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;
--- /dev/null
+#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;
+}
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;
--- /dev/null
+#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;
+ }
+}
#include <script.h>\r
#include <random.h>\r
#include <keypad.h>\r
+#include <flash.h>\r
\r
extern uint8_t _ebss;\r
extern char *itoa(int, char *, int);\r
{\r
asm("cpsid i");\r
// disable cached writes for precise debug info\r
- //*((uint32_t *)0xE000E008) |= 2;\r
+ *((uint32_t *)0xE000E008) |= 2;\r
\r
// prepare flash latency for 80MHz operation\r
FLASH->ACR &= ~(FLASH_ACR_LATENCY);\r
dsp_cursoron();\r
task_start(task_interpreter, 4096);\r
\r
+ /*char buf[2];\r
+ flash_init();\r
+ buf[0] = 'A';\r
+ flash_write(buf, 0, 1);\r
+ buf[0] = 0;\r
+ flash_read(buf, 0x00000000, 1);\r
+ buf[0] += ' ';\r
+ buf[1] = '\0';\r
+ dsp_puts(buf);*/\r
+\r
while (1) {\r
- gpio_dout(GPIOA, 5,\r
- (keypad_isdown(K0)));\r
- delay(10);\r
- /*gpio_dout(GPIOA, 5, 1);\r
+ //gpio_dout(GPIOA, 5,\r
+ // (keypad_isdown(K0)));\r
+ //delay(10);\r
+ gpio_dout(GPIOA, 5, 1);\r
delay(250);\r
gpio_dout(GPIOA, 5, 0);\r
- delay(250);*/\r
+ delay(250);\r
}\r
}\r
\r
\r
char *s = initrd_getfile("init");\r
if (s == 0) {\r
- dsp_puts("init not found");\r
+ dsp_puts("can't find init");\r
goto end;\r
}\r
\r
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)
{
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));
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 {
variable *v = igetarg(it, 0);
v->valtype = STRING;
- v->svalue = s;
+ v->value.p = (uint32_t)s;
return 0;
}
{
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;
+}
break;
case 'f':
itoa((int)va_arg(args, double), nbuf, 10);
+ continue;
break;
default:
buf[off++] = format[i];
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];
}