121 lines
2.5 KiB
C
121 lines
2.5 KiB
C
#ifndef MCU_HAL_H_
|
|
#define MCU_HAL_H_
|
|
|
|
/**** Includes ****/
|
|
#include <stdint.h>
|
|
|
|
/**** Public definitions ****/
|
|
/*
|
|
GPIO0 Down
|
|
GPIO1 Up
|
|
GPIO2 Mode
|
|
GPIO3 Handbrake
|
|
GPIO4 Brakes
|
|
GPIO5 Dimm
|
|
GPIO6 LED0
|
|
GPIO7 LED1
|
|
GPIO8 LED2
|
|
GPIO9 LED3
|
|
GPIO10 LED4
|
|
GPIO11 LED5
|
|
GPIO12 DCCD Enable
|
|
GPIO13 Handbrake pull
|
|
GPIO14 Speed pull
|
|
GPIO15 DCCD PWM
|
|
GPIO16 LED PWM
|
|
|
|
ADC0 Output current
|
|
ADC1 Output voltage
|
|
ADC2 Battery current
|
|
ADC3 Battery voltage
|
|
ADC4 Potentiometer
|
|
ADC5 Mode
|
|
ADC8 MCU temperature
|
|
ADC14 MCU internal reference
|
|
ADC15 MCU ground
|
|
*/
|
|
|
|
#define MCU_GPIO0 0 //Mode
|
|
#define MCU_GPIO1 1 //Pot
|
|
#define MCU_GPIO2 2 //Down
|
|
#define MCU_GPIO3 3 //Up
|
|
#define MCU_GPIO4 4 //Dimm
|
|
#define MCU_GPIO5 5 //Brakes
|
|
#define MCU_GPIO6 6 //Handbrake
|
|
#define MCU_GPIO7 7 //Handbrake pull
|
|
#define MCU_GPIO8 8 //Speed pull
|
|
#define MCU_GPIO9 9 //LED0
|
|
#define MCU_GPIO10 10 //LED1
|
|
#define MCU_GPIO11 11 //LED2
|
|
#define MCU_GPIO12 12 //LED3
|
|
#define MCU_GPIO13 13 //LED4
|
|
#define MCU_GPIO14 14 //LED5
|
|
#define MCU_GPIO15 15 //DCCD Enable
|
|
#define MCU_GPIO16 16 //DCCD PWM
|
|
#define MCU_GPIO17 17 //LED PWM
|
|
|
|
#define MCU_GPIO_LOW 0
|
|
#define MCU_GPIO_HIGH 1
|
|
#define MCU_GPIO_HIZ -1
|
|
|
|
#define MCU_ADC0 0 //Output current
|
|
#define MCU_ADC1 1 //Output voltage
|
|
#define MCU_ADC2 2 //Battery voltage
|
|
#define MCU_ADC3 3 //Battery current
|
|
#define MCU_ADC4 4 //Potentiometer
|
|
#define MCU_ADC5 5 //Mode
|
|
#define MCU_ADC8 8 //MCU temperature
|
|
#define MCU_ADC14 14 //MCU internal reference
|
|
#define MCU_ADC15 15 //MCU ground
|
|
|
|
#define MCU_PWM0 0 //DCCD
|
|
#define MCU_PWM1 1 //LED
|
|
|
|
//ADC definitions
|
|
typedef enum {
|
|
MCU_ADC_DIV2 = 0x01,
|
|
MCU_ADC_DIV4 = 0x02,
|
|
MCU_ADC_DIV8 = 0x03,
|
|
MCU_ADC_DIV16 = 0x04,
|
|
MCU_ADC_DIV32 = 0x05,
|
|
MCU_ADC_DIV64 = 0x06,
|
|
MCU_ADC_DIV128 = 0x07
|
|
} adcClkDiv_t;
|
|
|
|
//Timer definitions
|
|
typedef enum {
|
|
MCU_TIM_DIV1 = 0x01,
|
|
MCU_TIM_DIV8 = 0x02,
|
|
MCU_TIM_DIV64 = 0x03,
|
|
MCU_TIM_DIV256 = 0x04,
|
|
MCU_TIM_DIV1024 = 0x05
|
|
} timerClkDiv_t;
|
|
|
|
typedef struct {
|
|
adcClkDiv_t adc_clk;
|
|
timerClkDiv_t pwm_clk;
|
|
uint16_t pwm_top;
|
|
uint8_t pwm_chb_en;
|
|
} startupCfg_t;
|
|
|
|
/**** Public function declarations ****/
|
|
void mcu_startup(startupCfg_t* hwCfg);
|
|
|
|
uint8_t mcu_gpio_read(uint8_t ch);
|
|
void mcu_gpio_write(uint8_t ch, int8_t lvl);
|
|
|
|
uint16_t mcu_adc_read(uint8_t ch);
|
|
|
|
void mcu_pwm_write(uint8_t ch, uint16_t dc);
|
|
uint16_t mcu_pwm_read(uint8_t ch);
|
|
|
|
uint8_t mcu_ee_read8b(uint16_t address);
|
|
uint16_t mcu_ee_read16b(uint16_t address);
|
|
uint32_t mcu_ee_read32b(uint16_t address);
|
|
|
|
void mcu_ee_write8b(uint16_t address, uint8_t value);
|
|
void mcu_ee_write16b(uint16_t address, uint16_t value);
|
|
void mcu_ee_write32b(uint16_t address, uint32_t value);
|
|
|
|
#endif /* MCU_HAL_H_ */
|