basic graphing
This commit is contained in:
parent
77338a6b34
commit
a774e33cef
@ -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);
|
||||
|
||||
|
11
include/flash.h
Normal file
11
include/flash.h
Normal file
@ -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_
|
38
initrd/init
38
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."
|
||||
|
21
initrd/init2
Normal file
21
initrd/init2
Normal file
@ -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"
|
||||
|
1
initrd/init3
Normal file
1
initrd/init3
Normal file
@ -0,0 +1 @@
|
||||
print "Hello, world!"
|
BIN
libinterp.a
BIN
libinterp.a
Binary file not shown.
@ -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;
|
||||
|
95
src/flash.c
Normal file
95
src/flash.c
Normal file
@ -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;
|
||||
}
|
@ -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;
|
||||
|
52
src/keypad.c.bak
Normal file
52
src/keypad.c.bak
Normal file
@ -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;
|
||||
}
|
||||
}
|
25
src/main.c
25
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;
|
||||
}
|
||||
|
||||
|
39
src/script.c
39
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;
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user