- Initial commit of base firmware - which is still very raw
This commit is contained in:
174
Firmware/main.c
Normal file
174
Firmware/main.c
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* main.c
|
||||
*
|
||||
* Created: Mon Nov 08 2021 14:06:53
|
||||
* Author Chris
|
||||
*/
|
||||
|
||||
// ============================================================================================
|
||||
// Includes
|
||||
#include <stdio.h>
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
#include "I2C_Master.h"
|
||||
#include "UI_Control.h"
|
||||
#include "Rotary_Encoder.h"
|
||||
|
||||
#include "Display.h"
|
||||
#include "Display_SPI.h"
|
||||
#include "Display_Shapes.h"
|
||||
#include "Screens.h"
|
||||
|
||||
#include "USB_Serial.h"
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// Defines
|
||||
#define LEDG_PIN 12
|
||||
#define LEDG_CONFIG gpio_init(LEDG_PIN); gpio_set_dir(LEDG_PIN, GPIO_OUT)
|
||||
#define LEDG_ON gpio_put(LEDG_PIN, 0)
|
||||
#define LEDG_OFF gpio_put(LEDG_PIN, 1)
|
||||
#define LEDG_TOGGLE gpio_put(LEDG_PIN, !gpio_get(LEDG_PIN))
|
||||
#define LEDG_ANIMATION_1 LEDG_ON; sleep_ms(100); LEDG_OFF; sleep_ms(100);
|
||||
#define LEDG_ANIMATION_3 LEDG_ANIMATION_1; LEDG_ANIMATION_1; LEDG_ANIMATION_1
|
||||
|
||||
#define LEDR_PIN 11
|
||||
#define LEDR_CONFIG gpio_init(LEDR_PIN); gpio_set_dir(LEDR_PIN, GPIO_OUT)
|
||||
#define LEDR_ON gpio_put(LEDR_PIN, 0)
|
||||
#define LEDR_OFF gpio_put(LEDR_PIN, 1)
|
||||
#define LEDR_TOGGLE gpio_put(LEDR_PIN, !gpio_get(LEDR_PIN))
|
||||
|
||||
#define TRIGGER_PIN 18
|
||||
#define TRIGGER_CONFIG gpio_init(TRIGGER_PIN); gpio_set_dir(TRIGGER_PIN, GPIO_OUT)
|
||||
#define TRIGGER_ON gpio_put(TRIGGER_PIN, 1)
|
||||
#define TRIGGER_OFF gpio_put(TRIGGER_PIN, 0)
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// Variables
|
||||
volatile bool _Timer_Fired = false;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// Function Declarations
|
||||
void Check_For_Serial_Input(void);
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
Interrupt Service Routines
|
||||
*******************************************************************/
|
||||
bool ISR_Repeating_Timer(struct repeating_timer *t)
|
||||
{
|
||||
LEDG_TOGGLE;
|
||||
_Timer_Fired = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
Main Routine
|
||||
*******************************************************************/
|
||||
int main(void)
|
||||
{
|
||||
// LED =================================================
|
||||
LEDG_CONFIG;
|
||||
LEDR_CONFIG; LEDR_OFF;
|
||||
LEDG_ANIMATION_3;
|
||||
|
||||
// Trigger =================================================
|
||||
TRIGGER_CONFIG;
|
||||
TRIGGER_OFF;
|
||||
|
||||
// USB Serial =================================================
|
||||
USB_Serial_Init();
|
||||
|
||||
// Rotary Encoder =============================================
|
||||
Rotary_Encoder_Init();
|
||||
|
||||
// I2C Master =============================================
|
||||
I2CM_Init(false);
|
||||
|
||||
// UI Control =================================================
|
||||
UI_Control_Init();
|
||||
|
||||
// Display =================================================
|
||||
Display_Init(DISPLAY_COLOR_BLACK, true, false);
|
||||
// Screen_Setup_Loading();
|
||||
Screen_Setup_Menu_Main(TRANSITION_NONE, TRANSITION_NONE, LINEAR, 0, false, 0);
|
||||
|
||||
// Repeating Timer =============================================
|
||||
struct repeating_timer Timer;
|
||||
add_repeating_timer_ms(40, ISR_Repeating_Timer, NULL, &Timer);
|
||||
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (_Timer_Fired == true)
|
||||
{
|
||||
_Timer_Fired = false;
|
||||
|
||||
Display_Send_Buffer();
|
||||
Display_Inc_Frame_Counter();
|
||||
|
||||
Display_Screen_Transition_Tick();
|
||||
_Screen_Tick();
|
||||
|
||||
UI_Control_Acceleration_Update(CURRENT_TIME_ms);
|
||||
}
|
||||
|
||||
// Add functions here to execute during the DMA Transfer
|
||||
if(Display_SPI_DMA_Transfer_Ongoing())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if(Display_Send_Buffer_Completed())
|
||||
{
|
||||
TRIGGER_ON;
|
||||
Display_Render_Objects();
|
||||
TRIGGER_OFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
Check_For_Serial_Input();
|
||||
|
||||
if(Rotary_Encoder_Rotation_CW_Occurred()) {
|
||||
Display_Action_CW();
|
||||
}
|
||||
|
||||
if(Rotary_Encoder_Rotation_CCW_Occurred()) {
|
||||
Display_Action_CCW();
|
||||
}
|
||||
|
||||
if(Rotary_Encoder_Switch_Press_Occurred()) {
|
||||
Display_Action_SW();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Check_For_Serial_Input(void)
|
||||
{
|
||||
while(USB_Serial_Available())
|
||||
{
|
||||
uint8_t USB_Data = USB_Serial_Get_Byte();
|
||||
switch(USB_Data)
|
||||
{
|
||||
case 'a':
|
||||
USB_SERIAL_SEND_STRING("SPI Baudrate: ");
|
||||
USB_Serial_Send_Int_Dec(Display_SPI_Get_Baudrate(), 10);
|
||||
USB_SERIAL_SEND_TERMINATOR();
|
||||
break;
|
||||
|
||||
default:
|
||||
USB_SERIAL_SEND_STRING("Unknown Command: ");
|
||||
USB_Serial_Put_Char(USB_Data);
|
||||
USB_SERIAL_SEND_STRING(" (");
|
||||
USB_Serial_Send_Int_Hex(USB_Data, 2, true);
|
||||
USB_SERIAL_SEND_STRING(")");
|
||||
USB_SERIAL_SEND_TERMINATOR();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user