-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable display and add st7735 implementation
- Loading branch information
Showing
12 changed files
with
1,081 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "board_api.h" | ||
|
||
#if (TINYUF2_DISPLAY == 1U) | ||
#include "components/st7735/st7735.h" | ||
|
||
SPI_HandleTypeDef _display_spi; | ||
#endif // TINYUF2_DISPLAY == 1U | ||
|
||
//--------------------------------------------------------------------+ | ||
// Board Display Callouts | ||
//--------------------------------------------------------------------+ | ||
#if (TINYUF2_DISPLAY == 1) | ||
void ST7735_Transmit(uint8_t * buffer, uint16_t len, uint32_t timeout) | ||
{ | ||
HAL_SPI_Transmit(&_display_spi, buffer, len, timeout); | ||
} | ||
|
||
void ST7735_Delay(uint32_t ms) | ||
{ | ||
HAL_Delay(ms); | ||
} | ||
#endif | ||
|
||
void board_display_init(void) | ||
{ | ||
#if (TINYUF2_DISPLAY == 1U) | ||
display_init(&_display_spi); | ||
ST7735_Init(); | ||
// Clear previous screen | ||
ST7735_FillScreen(ST7735_BLACK); | ||
#endif // TINYUF2_DISPLAY == 1U | ||
} | ||
|
||
// The application draws a complete frame in memory and sends it | ||
// line-by-line to the display | ||
void board_display_draw_line(int y, uint16_t* pixel_color, uint32_t pixel_num) | ||
{ | ||
#if (TINYUF2_DISPLAY == 1U) | ||
for (uint32_t x = 0; x < pixel_num; x += 1) { | ||
ST7735_DrawPixel(y, x, pixel_color[x]); | ||
} | ||
#endif // TINYUF2_DISPLAY == 1U | ||
} | ||
|
||
|
||
//--------------------------------------------------------------------+ | ||
// LED pattern | ||
//--------------------------------------------------------------------+ | ||
void board_led_write(uint32_t state) | ||
{ | ||
#if defined(TINYUF2_LED) | ||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? GPIO_PIN_SET : GPIO_PIN_RESET); | ||
#endif // defined(LED_PIN) | ||
} | ||
|
||
//--------------------------------------------------------------------+ | ||
// Button | ||
//--------------------------------------------------------------------+ | ||
uint32_t board_button_read(void) | ||
{ | ||
#if defined(BUTTON_PIN) | ||
return (BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) ? 1: 0; | ||
#endif // defined(BUTTON_PIN) | ||
} | ||
|
||
//--------------------------------------------------------------------+ | ||
// Neopixel color for status | ||
//--------------------------------------------------------------------+ | ||
void board_rgb_write(uint8_t const rgb[]) | ||
{ | ||
// TODO: copy neopixel code from f4 port | ||
(void) rgb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "board_api.h" | ||
#include "tusb.h" | ||
|
||
#ifndef TINYUF2_SELF_UPDATE | ||
|
||
//--------------------------------------------------------------------+ | ||
// Core Interrupts | ||
//--------------------------------------------------------------------+ | ||
|
||
// Forward USB interrupt events to TinyUSB IRQ Handler | ||
// void OTG_HS_EP1_OUT_IRQHandler(void) | ||
// void OTG_HS_EP1_IN_IRQHandler(void) | ||
// void OTG_HS_WKUP_IRQHandler(void) | ||
// void OTG_FS_EP1_OUT_IRQHandler(void) | ||
// void OTG_FS_EP1_IN_IRQHandler(void) | ||
// void OTG_FS_WKUP_IRQHandler(void) | ||
|
||
void OTG_FS_IRQHandler(void) | ||
{ | ||
tud_int_handler(0); | ||
} | ||
|
||
void OTG_HS_IRQHandler(void) | ||
{ | ||
tud_int_handler(1); | ||
} | ||
#endif | ||
|
||
//--------------------------------------------------------------------+ | ||
// Core Exceptions | ||
//--------------------------------------------------------------------+ | ||
void SysTick_Handler(void) | ||
{ | ||
HAL_IncTick(); | ||
board_timer_handler(); | ||
} | ||
|
||
#define TRAP_EXC | ||
#if defined(TRAP_EXC) | ||
|
||
typedef struct __attribute__((packed)) CtxFrame { | ||
uint32_t r0; | ||
uint32_t r1; | ||
uint32_t r2; | ||
uint32_t r3; | ||
uint32_t r12; | ||
uint32_t lr; | ||
uint32_t ret; | ||
uint32_t xpsr; | ||
} sFrame; | ||
|
||
#define HARDFAULT_HANDLER(_x) \ | ||
asm volatile("tst lr, #4 \n" \ | ||
"ite eq \n" \ | ||
"mrseq r0, msp \n" \ | ||
"mrsne r0, psp \n" \ | ||
"b fault_handler \n") | ||
|
||
#define R ": %lx" | ||
#define EXC_FMT "r0" R "r1" R "r2" R "r3" R "r12" R "lr" R "ret" R "xpsr" R "\n" | ||
#define EXC_DET(x) x->r0, x->r1, x->r2, x->r3, x->r12, x->lr, x->ret, x->xpsr | ||
|
||
__attribute__((optimize("O0"))) | ||
void fault_handler(sFrame *fr) | ||
{ | ||
printf(EXC_FMT, EXC_DET(fr)); | ||
asm("bkpt #0"); | ||
} | ||
|
||
void HardFault_Handler(void) | ||
{ | ||
HARDFAULT_HANDLER(); | ||
} | ||
#endif // defined(TRAP_EXC) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.