basic graphing

master
Clyne Sullivan 7 years ago
parent 77338a6b34
commit a774e33cef

@ -5,6 +5,7 @@
void dsp_cursoron(void); 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_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); void dsp_rect(int x, int y, int w, int h, uint16_t color);

@ -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_

@ -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."

@ -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"

@ -0,0 +1 @@
print "Hello, world!"

Binary file not shown.

@ -100,6 +100,15 @@ void dsp_rect(int x, int y, int w, int h, uint16_t color)
UNLOCK; 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) void dsp_line(int x, int y, int i, int j, uint16_t color)
{ {
int dx = i - x; int dx = i - x;
@ -115,11 +124,7 @@ void dsp_line(int x, int y, int i, int j, uint16_t color)
int e2; int e2;
while (1) { while (1) {
LOCK; dsp_pixel(x, y, color);
dsp_set_addr(x, y, x, y);
dsp_write_data(color >> 8);
dsp_write_data(color & 0xFF);
UNLOCK;
if (x == i && y == j) if (x == i && y == j)
break; break;
e2 = err; e2 = err;

@ -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; return file;
uint32_t size = initrd_getsize(file) + sizeof(initrd_file); uint32_t size = initrd_getsize(file) + sizeof(initrd_file);
offset += size; offset += size;
file += size; file = (initrd_file *)((uint8_t *)file + size + 1);
} }
return 0; return 0;

@ -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;
}
}

@ -13,6 +13,7 @@
#include <script.h> #include <script.h>
#include <random.h> #include <random.h>
#include <keypad.h> #include <keypad.h>
#include <flash.h>
extern uint8_t _ebss; extern uint8_t _ebss;
extern char *itoa(int, char *, int); extern char *itoa(int, char *, int);
@ -24,7 +25,7 @@ int main(void)
{ {
asm("cpsid i"); asm("cpsid i");
// disable cached writes for precise debug info // disable cached writes for precise debug info
//*((uint32_t *)0xE000E008) |= 2; *((uint32_t *)0xE000E008) |= 2;
// prepare flash latency for 80MHz operation // prepare flash latency for 80MHz operation
FLASH->ACR &= ~(FLASH_ACR_LATENCY); FLASH->ACR &= ~(FLASH_ACR_LATENCY);
@ -58,14 +59,24 @@ void kmain(void)
dsp_cursoron(); dsp_cursoron();
task_start(task_interpreter, 4096); 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) { while (1) {
gpio_dout(GPIOA, 5, //gpio_dout(GPIOA, 5,
(keypad_isdown(K0))); // (keypad_isdown(K0)));
delay(10); //delay(10);
/*gpio_dout(GPIOA, 5, 1); gpio_dout(GPIOA, 5, 1);
delay(250); delay(250);
gpio_dout(GPIOA, 5, 0); gpio_dout(GPIOA, 5, 0);
delay(250);*/ delay(250);
} }
} }
@ -77,7 +88,7 @@ void task_interpreter(void)
char *s = initrd_getfile("init"); char *s = initrd_getfile("init");
if (s == 0) { if (s == 0) {
dsp_puts("init not found"); dsp_puts("can't find init");
goto end; goto end;
} }

@ -19,6 +19,7 @@ int script_line(interpreter *it);
int script_color(interpreter *it); int script_color(interpreter *it);
int script_rand(interpreter *it); int script_rand(interpreter *it);
int script_getkey(interpreter *it); int script_getkey(interpreter *it);
int script_pixel(interpreter *it);
void script_loadlib(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, "color", script_color);
inew_cfunc(it, "rand", script_rand); inew_cfunc(it, "rand", script_rand);
inew_cfunc(it, "getkey", script_getkey); inew_cfunc(it, "getkey", script_getkey);
inew_cfunc(it, "pixel", script_pixel);
} }
int script_puts(interpreter *it) int script_puts(interpreter *it)
{ {
char *s = igetarg_string(it, 0); const char *s = igetarg_string(it, 0);
dsp_puts(s); dsp_puts(s);
//dsp_puts("\n"); //dsp_puts("\n");
//asm("mov r0, %0; svc 2" :: "r" (s)); //asm("mov r0, %0; svc 2" :: "r" (s));
@ -44,7 +46,8 @@ int script_puts(interpreter *it)
int script_gets(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; uint16_t index = 0;
do { do {
@ -57,7 +60,7 @@ int script_gets(interpreter *it)
variable *v = igetarg(it, 0); variable *v = igetarg(it, 0);
v->valtype = STRING; v->valtype = STRING;
v->svalue = s; v->value.p = (uint32_t)s;
return 0; return 0;
} }
@ -98,39 +101,33 @@ int script_color(interpreter *it)
{ {
uint16_t c = dsp_color(igetarg_integer(it, 0), igetarg_integer(it, 1), uint16_t c = dsp_color(igetarg_integer(it, 0), igetarg_integer(it, 1),
igetarg_integer(it, 2)); igetarg_integer(it, 2));
variable v; variable *v = make_varn(0, (float)c);
v.valtype = INTEGER; iret(it, v);
INT(&v) = c; free(v);
v.svalue = 0;
isetstr(&v);
iret(it, &v);
return 0; return 0;
} }
int script_rand(interpreter *it) int script_rand(interpreter *it)
{ {
variable *v = (variable *)malloc(sizeof(variable));
unsigned int mod = igetarg_integer(it, 0); unsigned int mod = igetarg_integer(it, 0);
unsigned int val = random_get(); unsigned int val = random_get();
v->valtype = INTEGER; variable *v = make_varn(0, (float)(mod % val));
INT(v) = val % mod;
v->svalue = 0;
isetstr(v);
iret(it, v); iret(it, v);
free(v->svalue);
free(v); free(v);
return 0; return 0;
} }
int script_getkey(interpreter *it) int script_getkey(interpreter *it)
{ {
variable *v = (variable *)malloc(sizeof(variable)); variable *v = make_varn(0, (float)keypad_get());
v->valtype = INTEGER;
INT(v) = keypad_get();
v->svalue = 0;
isetstr(v);
iret(it, v); iret(it, v);
free(v->svalue);
free(v); free(v);
return 0; 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; break;
case 'f': case 'f':
itoa((int)va_arg(args, double), nbuf, 10); itoa((int)va_arg(args, double), nbuf, 10);
continue;
break; break;
default: default:
buf[off++] = format[i]; buf[off++] = format[i];
@ -47,7 +48,7 @@ char *snprintf(char *buf, unsigned int max, const char *format, ...)
break; break;
} }
if (nbuf[0] != '\0') { 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++) nbuf[j] != '\0'; off++, j++)
buf[off] = nbuf[j]; buf[off] = nbuf[j];
} }

Loading…
Cancel
Save