Add start of TC and design for init image

This commit is contained in:
Sem van der Hoeven
2023-10-31 22:10:55 +01:00
parent 34fd5a5380
commit cf27e84969
5 changed files with 31 additions and 63 deletions

View File

@@ -71,79 +71,36 @@ void on_init_enter()
void on_init_run()
{
Serial.println("Running!");
if (!flag)
{
flag = 1;
main_color = ~main_color;
// display.clrScr();
if (main_color)
{
display.setColor(VGA_RED);
display.fillCircle(10,20,100);
} else
{
display.setColor(VGA_TEAL);
display.fillCircle(30,50,131);
}
display.setColor(VGA_AQUA);
display.setBackColor(0,0,0);
text_temp[0] = init_text[init_text_i];
display.print(text_temp, init_text_x, LCD_H / 2);
init_text_x += display.getFontXsize();
init_text_i++;
if (init_text_i > 14)
{
init_text_i = 0;
display.clrScr();
}
}
}
void on_init_exit()
{
Serial.println("Exiting init state!");
flag = 0;
main_color = 0;
display.clrScr();
}
void on_main_enter()
{
obd2_timer_reset();
obd2_RTT_reset();
Serial.println("Entering main loop");
obd2_timer_set_period(800);
}
void on_main_run()
{
if (!flag)
{
led_state = ~led_state;
digitalWrite(LED_BUILTIN, led_state);
flag = 1;
main_color = ~main_color;
if (main_color)
display.setColor(255, 0, 166);
else
display.setColor(78, 181, 72);
display.fillRect(LCD_W / 2 - 200, LCD_H / 2 - 100, LCD_W / 2 + 200, LCD_H / 2 + 100);
display.setColor(0, 247, 255);
display.print("OBD2 display yeet", CENTER, LCD_H / 2);
#if (DEBUG == 1)
Serial.println("switching led");
#endif
}
}
void RTT_Handler()
{
flag = 0;
obd2_timer_reset();
obd2_RTT_reset();
}
void setup()
{
/* TODO change for TRNG (section 42 of datasheet)*/
randomSeed(analogRead(0));
#if (DEBUG == 1)
@@ -162,7 +119,7 @@ void setup()
pinMode(LED_BUILTIN, OUTPUT);
obd2_timer_init();
obd2_RTT_init();
statemachine_register_state(&init_state, STATE_INIT);
statemachine_register_state(&main_state, STATE_CAR_INFO);
statemachine_init();

View File

@@ -1,10 +1,6 @@
#include "sam3xa/include/sam3x8e.h"
#include "sam3xa/include/component/component_rtt.h"
// #include "sam3xa/include/component/component_rtt.h"
// #include "sam3xa/include/sam3x8e.h"
#include "obd2_timer.h"
void obd2_timer_init(void)
void obd2_RTT_init(void)
{
/* enable the timer: reset the RTT
RTT->RTT_MR = RTT_MR_RTTRST;
@@ -12,16 +8,16 @@ void obd2_timer_init(void)
RTT->RTT_AR = 0;
}
void obd2_timer_enable()
void obd2_RTT_enable()
{
/* enable the alarm interrupt*/
RTT->RTT_MR |= RTT_MR_ALMIEN;
/* enable the alarm interrupt and set the prescaler to the processor frequency to generate an interrupt every second*/
RTT->RTT_MR |= RTT_MR_ALMIEN | RTT_MR_RTPRES(CLOCK_FREQ);
/* enable the interrupt*/
NVIC_EnableIRQ(RTT_IRQn);
}
void obd2_timer_reset()
void obd2_RTT_reset()
{
/* To prevent several executions of the interrupt handler,
the interrupt must be disabled in the interrupt handler
@@ -41,8 +37,14 @@ void obd2_timer_reset()
RTT->RTT_MR |= RTT_MR_RTTRST;
}
void obd2_timer_set_period(__UINT32_TYPE__ period)
void obd2_RTT_set_period(__UINT32_TYPE__ period)
{
/* set the prescaler value equal to the clock speed divided by how many milliseconds*/
RTT->RTT_MR |= RTT_MR_RTPRES(CLOCK_FREQ / (1000/period));
}
void obd2_TC_init()
{
/* enable the timer/counter 0*/
TC0->TC_CHANNEL[0].TC_CCR |= TC_CCR_CLKEN;
}

View File

@@ -10,10 +10,12 @@ extern "C"
#define CLOCK_FREQ 32768
void obd2_timer_init();
void obd2_timer_reset();
void obd2_timer_enable();
void obd2_timer_set_period(__UINT32_TYPE__ period);
void obd2_RTT_init();
void obd2_RTT_reset();
void obd2_RTT_enable();
void obd2_RTT_set_period(__UINT32_TYPE__ period);
void obd2_TC_init();
#ifdef __cplusplus
}

BIN
img/design_init_display.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

View File

@@ -21,3 +21,10 @@
- [Product link](https://www.tinytronics.nl/shop/en/displays/tft/3.5-inch-tft-display-320*480-pixels-mega-compatible-ili9486)
- [UTFT library](http://www.rinkydinkelectronics.com/library.php?id=51)
- [SdFat library](https://github.com/greiman/SdFat)
## Design
### INIT display
![init design](img/design_init_display.png)
red = animation, yellow is order of appearance