From 9889fcc1c3583e045bcf27160bbd8ea3747eea93 Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Sun, 18 Sep 2022 21:41:38 -0700 Subject: [PATCH 1/5] hagl test --- src/os/boot.c | 457 ++++++++++++++++++++++++++------------------------ 1 file changed, 237 insertions(+), 220 deletions(-) diff --git a/src/os/boot.c b/src/os/boot.c index b65152f..d2753e2 100644 --- a/src/os/boot.c +++ b/src/os/boot.c @@ -16,228 +16,245 @@ #include "kernel/kernel.h" -const uint LED_PIN = 14; -volatile extern uint32_t tickct; -volatile extern int32_t sleep_time; -volatile extern int32_t sleep_core; -volatile extern int32_t sleep_ct; - - semaphore_t talking_stick; - -/* - * This task blinks the LED. It also holds the semaphore talking_stick - * while the LED is off. This is used to gate the reporter task and keep it - * from printing. - */ -void blinker(void) { - gpio_init(LED_PIN); - gpio_set_dir(LED_PIN, GPIO_OUT); - while (true) { - gpio_put(LED_PIN, 1); - sem_release(&talking_stick); - piccolo_sleep(2000); - gpio_put(LED_PIN, 0); - sem_acquire_blocking(&talking_stick); - piccolo_sleep(2000); - } -} - - -int is_prime(unsigned int n) -{ - unsigned int p; - if (!(n & 1) || n < 2 ) return n == 2; +// const uint LED_PIN = 14; +// volatile extern uint32_t tickct; +// volatile extern int32_t sleep_time; +// volatile extern int32_t sleep_core; +// volatile extern int32_t sleep_ct; + +// semaphore_t talking_stick; + +// /* +// * This task blinks the LED. It also holds the semaphore talking_stick +// * while the LED is off. This is used to gate the reporter task and keep it +// * from printing. +// */ +// void blinker(void) { +// gpio_init(LED_PIN); +// gpio_set_dir(LED_PIN, GPIO_OUT); +// while (true) { +// gpio_put(LED_PIN, 1); +// sem_release(&talking_stick); +// piccolo_sleep(2000); +// gpio_put(LED_PIN, 0); +// sem_acquire_blocking(&talking_stick); +// piccolo_sleep(2000); +// } +// } + + +// int is_prime(unsigned int n) +// { +// unsigned int p; +// if (!(n & 1) || n < 2 ) return n == 2; - // comparing p*p <= n can overflow - for (p = 3; p <= n/p; p += 2) - if (!(n % p)) return 0; - return 1; -} - -/* - * Prime number computing task. Just to burn CPU time - * Note that it never calls piccolo_yield() - */ -uint32_t primes[2], totalPrimes; -piccolo_os_task_t * reporter; - -void find_primes(void) { - int p; - - printf("task2: Created!\n"); - while (1) { - for (p=5;p;p+=2) if(is_prime(p)==1) { - totalPrimes++; - primes[get_core_num()]++; - // every 4096 prime numbers, send the reporter a signal - if(!(totalPrimes & 0xFFF)) piccolo_send_signal(reporter); - } - } -} -/* - * Report on the progress of the prime number finder. Wait until he sends a signal - * Then get the "talking stick" semaphore from the LED blinker task. We can only - * talk when the green light is on! Then print a report. We also report on - * how many tasks the garbage collector has reclaimed using a counter which - * is only there as a debug feature at the moment... - */ -extern uint32_t kills; -void reporter_task(void){ - printf("Reporter Started\n"); - while(1) { - piccolo_get_signal_all_blocking(); - if(!sem_acquire_timeout_ms(&talking_stick,10000)) printf("sem acquire timeout SHOULD NOT have failed\n"); +// // comparing p*p <= n can overflow +// for (p = 3; p <= n/p; p += 2) +// if (!(n % p)) return 0; +// return 1; +// } + +// /* +// * Prime number computing task. Just to burn CPU time +// * Note that it never calls piccolo_yield() +// */ +// uint32_t primes[2], totalPrimes; +// piccolo_os_task_t * reporter; + +// void find_primes(void) { +// int p; + +// printf("task2: Created!\n"); +// while (1) { +// for (p=5;p;p+=2) if(is_prime(p)==1) { +// totalPrimes++; +// primes[get_core_num()]++; +// // every 4096 prime numbers, send the reporter a signal +// if(!(totalPrimes & 0xFFF)) piccolo_send_signal(reporter); +// } +// } +// } +// /* +// * Report on the progress of the prime number finder. Wait until he sends a signal +// * Then get the "talking stick" semaphore from the LED blinker task. We can only +// * talk when the green light is on! Then print a report. We also report on +// * how many tasks the garbage collector has reclaimed using a counter which +// * is only there as a debug feature at the moment... +// */ +// extern uint32_t kills; +// void reporter_task(void){ +// printf("Reporter Started\n"); +// while(1) { +// piccolo_get_signal_all_blocking(); +// if(!sem_acquire_timeout_ms(&talking_stick,10000)) printf("sem acquire timeout SHOULD NOT have failed\n"); - printf("Total primes %d, cores 0/1 %d/%d kills %d recycled %d bytes\n", - totalPrimes,primes[0], primes[1], kills, kills*sizeof(piccolo_os_task_t)); - sem_release(&talking_stick); - } -} - -/* - * The next two tasks are created periodically by the stress_tester task - * only to quickly delete themselves. "z" dies immediatly whicle "sz" yields - * once first. - */ -void sz(){ - piccolo_yield(); - return; -} - -void z(){ - int a = 1; - return; -} - -void stress_tester(void) { - /** - * Force a slew of task create and deletes by creating lots of tasks - * that die very quickly. Do this every few seconds. Note that we - * are perfectly safe creating multiple tasks running the same function - * since they all have seperate stacks. - * - */ - while(1) { - piccolo_create_task(z); - piccolo_create_task(z); - piccolo_create_task(z); - piccolo_create_task(sz); - piccolo_create_task(sz); - piccolo_create_task(sz); - piccolo_create_task(z); - piccolo_create_task(sz); - piccolo_create_task(z); - piccolo_create_task(sz); - piccolo_create_task(sz); - - piccolo_sleep(3000); - } -} - - -void spinner2(void){ - piccolo_os_task_t * task; - task = piccolo_get_task_id(); - while(!piccolo_get_signal()) piccolo_yield(); // spin until we get a signal - piccolo_get_signal_blocking(); // hang until we get a second one -// printf(" signal hang2 task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); - piccolo_get_signal_blocking(); // hang until we get a third one -// printf(" semaphore hang task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); - sem_acquire_blocking(&talking_stick); // then hang on the semaphore -// printf(" semaphore exit task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); - return; // and exit -} -void spinner(){ - int i,yielding=1,blocking=1, semaphore; - absolute_time_t start; - uint64_t time; - piccolo_os_task_t *spin1, *spin2; -#define loops 1000 - piccolo_sleep(10); - start = get_absolute_time(); - for(i=0;isignal_in,task->signal_out,task->signal_limit); +// piccolo_get_signal_blocking(); // hang until we get a third one +// // printf(" semaphore hang task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); +// sem_acquire_blocking(&talking_stick); // then hang on the semaphore +// // printf(" semaphore exit task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); +// return; // and exit +// } +// void spinner(){ +// int i,yielding=1,blocking=1, semaphore; +// absolute_time_t start; +// uint64_t time; +// piccolo_os_task_t *spin1, *spin2; +// #define loops 1000 +// piccolo_sleep(10); +// start = get_absolute_time(); +// for(i=0;i +#include int main() { - stdio_init_all(); - piccolo_init(); - - - sleep_ms(5000); // pause to give user a chance to start putty - - printf("Hello World!\n"); - - // initialize the semaphore - sem_init(&talking_stick,1,1); - - // test a few things for timing first - // the spinner task will start everything else ... - piccolo_create_task(spinner); - - printf("PICCOLO OS Demo Starting...\n"); - // and begin! - piccolo_start(); + for (uint16_t i = 1; i < 10; i++) { + int16_t x0 = rand() % DISPLAY_WIDTH; + int16_t y0 = rand() % DISPLAY_HEIGHT; + int16_t x1 = rand() % DISPLAY_WIDTH; + int16_t y1 = rand() % DISPLAY_HEIGHT; + color_t color = rand() % 0xffff; + + hagl_fill_rectangle(display, x0, y0, x1, y1, color); + } - return 0; /* Never gonna happen */ -} + return 0; +} \ No newline at end of file From 5323e32695e49ac04d314bf23fe43c2c5257bfd8 Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Mon, 19 Sep 2022 00:14:45 -0700 Subject: [PATCH 2/5] updated hagl --- src/os/boot.c | 33 +++++++++++++++++++++++---------- src/os/drivers/hagl/hagl | 2 +- src/os/drivers/hagl/hagl_hal | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/os/boot.c b/src/os/boot.c index d2753e2..77736fe 100644 --- a/src/os/boot.c +++ b/src/os/boot.c @@ -16,6 +16,9 @@ #include "kernel/kernel.h" +#include +#include + // const uint LED_PIN = 14; // volatile extern uint32_t tickct; // volatile extern int32_t sleep_time; @@ -242,19 +245,29 @@ // return 0; /* Never gonna happen */ // } -#include -#include +static hagl_backend_t *display; int main() { - for (uint16_t i = 1; i < 10; i++) { - int16_t x0 = rand() % DISPLAY_WIDTH; - int16_t y0 = rand() % DISPLAY_HEIGHT; - int16_t x1 = rand() % DISPLAY_WIDTH; - int16_t y1 = rand() % DISPLAY_HEIGHT; - color_t color = rand() % 0xffff; - - hagl_fill_rectangle(display, x0, y0, x1, y1, color); + display = hagl_init(); + + while (1) { + hagl_clear(display); + + for (uint16_t i = 1; i < 10; i++) { + int16_t x0 = rand() % DISPLAY_WIDTH; + int16_t y0 = rand() % DISPLAY_HEIGHT; + int16_t x1 = rand() % DISPLAY_WIDTH; + int16_t y1 = rand() % DISPLAY_HEIGHT; + color_t color = rand() % 0xffff; + + hagl_fill_rectangle(display, x0, y0, x1, y1, color); + } + + hagl_flush(display); + } + hagl_close(display); + return 0; } \ No newline at end of file diff --git a/src/os/drivers/hagl/hagl b/src/os/drivers/hagl/hagl index ea39012..341fd0a 160000 --- a/src/os/drivers/hagl/hagl +++ b/src/os/drivers/hagl/hagl @@ -1 +1 @@ -Subproject commit ea390121803dc6034c4908311471007d05dee0f3 +Subproject commit 341fd0a2b6ce972fb3bda46dbb7394b6e4bd3410 diff --git a/src/os/drivers/hagl/hagl_hal b/src/os/drivers/hagl/hagl_hal index ee06cb8..a05814a 160000 --- a/src/os/drivers/hagl/hagl_hal +++ b/src/os/drivers/hagl/hagl_hal @@ -1 +1 @@ -Subproject commit ee06cb8df6d65961a1cae908fbd7affcda77ee8e +Subproject commit a05814afa83fd43c0230abac4a102de9fec090ac From 529eb0dc0b93389d5a5236a9e10dde98c631b34b Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Mon, 19 Sep 2022 03:19:57 -0700 Subject: [PATCH 3/5] Made HAGL work At the set resolution, it causes a PANIC --- src/os/CMakeLists.txt | 28 ++++++++++++++++++++++++---- src/os/boot.c | 38 ++++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/os/CMakeLists.txt b/src/os/CMakeLists.txt index 5edf2a5..6ebb68f 100644 --- a/src/os/CMakeLists.txt +++ b/src/os/CMakeLists.txt @@ -25,14 +25,34 @@ target_link_libraries(boot hardware_exception hardware_sync pico_multicore - hagl_hal + hardware_spi + hardware_dma hagl + hagl_hal ) target_compile_definitions(boot PRIVATE - HAGL_HAL_USE_DOUBLE_BUFFER - HAGL_HAL_DEBUG + HAGL_HAL_USE_DOUBLE_BUFFER + HAGL_HAL_USE_DMA + HAGL_HAL_DEBUG + MIPI_DISPLAY_PIN_CS=9 + MIPI_DISPLAY_PIN_DC=8 + MIPI_DISPLAY_PIN_RST=12 + MIPI_DISPLAY_PIN_BL=13 + MIPI_DISPLAY_PIN_CLK=10 + MIPI_DISPLAY_PIN_MOSI=11 + MIPI_DISPLAY_PIN_MISO=-1 + MIPI_DISPLAY_SPI_PORT=spi1 +# MIPI_DISPLAY_SPI_CLOCK_SPEED_HZ=680000 + +# MIPI_DISPLAY_PIXEL_FORMAT=MIPI_DCS_PIXEL_FORMAT_16BIT +# MIPI_DISPLAY_ADDRESS_MODE=MIPI_DCS_ADDRESS_MODE_RGB + + MIPI_DISPLAY_WIDTH=320 + MIPI_DISPLAY_HEIGHT=480 + MIPI_DISPLAY_OFFSET_X=0 + MIPI_DISPLAY_OFFSET_Y=0 ) # create map/bin/hex/uf2 file in addition to ELF. -pico_add_extra_outputs(boot) \ No newline at end of file +pico_add_extra_outputs(boot) diff --git a/src/os/boot.c b/src/os/boot.c index 77736fe..7fe20e8 100644 --- a/src/os/boot.c +++ b/src/os/boot.c @@ -18,6 +18,7 @@ #include #include +#include // const uint LED_PIN = 14; // volatile extern uint32_t tickct; @@ -245,29 +246,30 @@ // return 0; /* Never gonna happen */ // } -static hagl_backend_t *display; - int main() { - display = hagl_init(); - - while (1) { - hagl_clear(display); - for (uint16_t i = 1; i < 10; i++) { - int16_t x0 = rand() % DISPLAY_WIDTH; - int16_t y0 = rand() % DISPLAY_HEIGHT; - int16_t x1 = rand() % DISPLAY_WIDTH; - int16_t y1 = rand() % DISPLAY_HEIGHT; - color_t color = rand() % 0xffff; + set_sys_clock_khz(133000, true); - hagl_fill_rectangle(display, x0, y0, x1, y1, color); - } + stdio_init_all(); + + hagl_backend_t *display = hagl_init(); - hagl_flush(display); + hagl_set_clip_window(display, 0, 20, DISPLAY_WIDTH - 100, DISPLAY_HEIGHT - 100); + hagl_clear(display); + + for (uint16_t i = 1; i < 1000; i++) { + int16_t x0 = rand() % DISPLAY_WIDTH - 100; + int16_t y0 = rand() % DISPLAY_HEIGHT; + int16_t x1 = rand() % DISPLAY_WIDTH - 100; + int16_t y1 = rand() % DISPLAY_HEIGHT; + color_t color = rand() % 0xffff; + + hagl_draw_line(display, x0, y0, x1, y1, color); } - hagl_close(display); - return 0; -} \ No newline at end of file + hagl_flush(display); + +} + From 9438f4efde23c0cf493350d851c9e1966dc10307 Mon Sep 17 00:00:00 2001 From: Bjorn <75190918+BjornTheProgrammer@users.noreply.github.com> Date: Tue, 20 Sep 2022 12:32:42 -0700 Subject: [PATCH 4/5] Piccolos_OS_Plus example HAGL Drawing --- src/os/CMakeLists.txt | 2 +- src/os/boot.c | 268 +++++------------------------------------- 2 files changed, 31 insertions(+), 239 deletions(-) diff --git a/src/os/CMakeLists.txt b/src/os/CMakeLists.txt index 6ebb68f..306e59b 100644 --- a/src/os/CMakeLists.txt +++ b/src/os/CMakeLists.txt @@ -32,7 +32,7 @@ target_link_libraries(boot ) target_compile_definitions(boot PRIVATE - HAGL_HAL_USE_DOUBLE_BUFFER + HAGL_HAL_USE_SINGLE_BUFFER HAGL_HAL_USE_DMA HAGL_HAL_DEBUG MIPI_DISPLAY_PIN_CS=9 diff --git a/src/os/boot.c b/src/os/boot.c index 7fe20e8..b2e2cff 100644 --- a/src/os/boot.c +++ b/src/os/boot.c @@ -8,11 +8,8 @@ #include "pico/stdlib.h" #include #include "pico/malloc.h" -#include "hardware/structs/systick.h" -#include "hardware/exception.h" #include "pico/multicore.h" #include "kernel/lock_core.h" -#include "pico/sem.h" #include "kernel/kernel.h" @@ -20,256 +17,51 @@ #include #include -// const uint LED_PIN = 14; -// volatile extern uint32_t tickct; -// volatile extern int32_t sleep_time; -// volatile extern int32_t sleep_core; -// volatile extern int32_t sleep_ct; +hagl_backend_t *display; -// semaphore_t talking_stick; - -// /* -// * This task blinks the LED. It also holds the semaphore talking_stick -// * while the LED is off. This is used to gate the reporter task and keep it -// * from printing. -// */ -// void blinker(void) { -// gpio_init(LED_PIN); -// gpio_set_dir(LED_PIN, GPIO_OUT); -// while (true) { -// gpio_put(LED_PIN, 1); -// sem_release(&talking_stick); -// piccolo_sleep(2000); -// gpio_put(LED_PIN, 0); -// sem_acquire_blocking(&talking_stick); -// piccolo_sleep(2000); -// } -// } - - -// int is_prime(unsigned int n) -// { -// unsigned int p; -// if (!(n & 1) || n < 2 ) return n == 2; - -// // comparing p*p <= n can overflow -// for (p = 3; p <= n/p; p += 2) -// if (!(n % p)) return 0; -// return 1; -// } - -// /* -// * Prime number computing task. Just to burn CPU time -// * Note that it never calls piccolo_yield() -// */ -// uint32_t primes[2], totalPrimes; -// piccolo_os_task_t * reporter; - -// void find_primes(void) { -// int p; - -// printf("task2: Created!\n"); -// while (1) { -// for (p=5;p;p+=2) if(is_prime(p)==1) { -// totalPrimes++; -// primes[get_core_num()]++; -// // every 4096 prime numbers, send the reporter a signal -// if(!(totalPrimes & 0xFFF)) piccolo_send_signal(reporter); -// } -// } -// } -// /* -// * Report on the progress of the prime number finder. Wait until he sends a signal -// * Then get the "talking stick" semaphore from the LED blinker task. We can only -// * talk when the green light is on! Then print a report. We also report on -// * how many tasks the garbage collector has reclaimed using a counter which -// * is only there as a debug feature at the moment... -// */ -// extern uint32_t kills; -// void reporter_task(void){ -// printf("Reporter Started\n"); -// while(1) { -// piccolo_get_signal_all_blocking(); -// if(!sem_acquire_timeout_ms(&talking_stick,10000)) printf("sem acquire timeout SHOULD NOT have failed\n"); - -// printf("Total primes %d, cores 0/1 %d/%d kills %d recycled %d bytes\n", -// totalPrimes,primes[0], primes[1], kills, kills*sizeof(piccolo_os_task_t)); -// sem_release(&talking_stick); -// } -// } - -// /* -// * The next two tasks are created periodically by the stress_tester task -// * only to quickly delete themselves. "z" dies immediatly whicle "sz" yields -// * once first. -// */ -// void sz(){ -// piccolo_yield(); -// return; -// } - -// void z(){ -// int a = 1; -// return; -// } - -// void stress_tester(void) { -// /** -// * Force a slew of task create and deletes by creating lots of tasks -// * that die very quickly. Do this every few seconds. Note that we -// * are perfectly safe creating multiple tasks running the same function -// * since they all have seperate stacks. -// * -// */ -// while(1) { -// piccolo_create_task(z); -// piccolo_create_task(z); -// piccolo_create_task(z); -// piccolo_create_task(sz); -// piccolo_create_task(sz); -// piccolo_create_task(sz); -// piccolo_create_task(z); -// piccolo_create_task(sz); -// piccolo_create_task(z); -// piccolo_create_task(sz); -// piccolo_create_task(sz); - -// piccolo_sleep(3000); -// } -// } - - -// void spinner2(void){ -// piccolo_os_task_t * task; -// task = piccolo_get_task_id(); -// while(!piccolo_get_signal()) piccolo_yield(); // spin until we get a signal -// piccolo_get_signal_blocking(); // hang until we get a second one -// // printf(" signal hang2 task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); -// piccolo_get_signal_blocking(); // hang until we get a third one -// // printf(" semaphore hang task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); -// sem_acquire_blocking(&talking_stick); // then hang on the semaphore -// // printf(" semaphore exit task %8X in %d out %d limit %d\n",task,task->signal_in,task->signal_out,task->signal_limit); -// return; // and exit -// } -// void spinner(){ -// int i,yielding=1,blocking=1, semaphore; -// absolute_time_t start; -// uint64_t time; -// piccolo_os_task_t *spin1, *spin2; -// #define loops 1000 -// piccolo_sleep(10); -// start = get_absolute_time(); -// for(i=0;i Date: Thu, 22 Sep 2022 05:11:54 -0700 Subject: [PATCH 5/5] Update hagl --- src/os/drivers/hagl/hagl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/drivers/hagl/hagl b/src/os/drivers/hagl/hagl index 341fd0a..8f533f2 160000 --- a/src/os/drivers/hagl/hagl +++ b/src/os/drivers/hagl/hagl @@ -1 +1 @@ -Subproject commit 341fd0a2b6ce972fb3bda46dbb7394b6e4bd3410 +Subproject commit 8f533f29799f29ed423571d4acc734a1906ac2d7