generated from Embedded_Projects/MPyATE_Template
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
daa2a698d2
commit
5e1cb6080f
|
@ -44,6 +44,7 @@ set(TARGET_SOURCES
|
||||||
"board/peripherals.c"
|
"board/peripherals.c"
|
||||||
"board/pin_mux.c"
|
"board/pin_mux.c"
|
||||||
"src/app_adc.c"
|
"src/app_adc.c"
|
||||||
|
"src/app_dac.c"
|
||||||
"src/app_i2c_if.c"
|
"src/app_i2c_if.c"
|
||||||
"src/app_gpio.c"
|
"src/app_gpio.c"
|
||||||
"src/app_reg_if.c"
|
"src/app_reg_if.c"
|
||||||
|
|
8
include/app_dac.h
Normal file
8
include/app_dac.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef APP_DAC_H
|
||||||
|
#define APP_DAC_H
|
||||||
|
|
||||||
|
void app_dac_init(void);
|
||||||
|
uint16_t app_dac_module_reg_read(uint8_t addr);
|
||||||
|
void app_dac_module_reg_write(uint8_t addr, uint16_t data);
|
||||||
|
|
||||||
|
#endif // APP_DAC_H
|
93
src/app_dac.c
Normal file
93
src/app_dac.c
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/* Board */
|
||||||
|
#include "clock_config.h"
|
||||||
|
#include "pin_mux.h"
|
||||||
|
|
||||||
|
/* SDK drivers */
|
||||||
|
#include "fsl_clock.h"
|
||||||
|
#include "fsl_dac.h"
|
||||||
|
#include "fsl_power.h"
|
||||||
|
|
||||||
|
/* Private */
|
||||||
|
#include "app_dac.h"
|
||||||
|
|
||||||
|
#define APP_DAC_REG_OFFSET_CTRL (0x00U)
|
||||||
|
#define APP_DAC_REG_OFFSET_DATA (0x01U)
|
||||||
|
|
||||||
|
#define APP_DAC_CTRL_BIAS_Pos (8U)
|
||||||
|
#define APP_DAC_CTRL_BIAS_Msk (1U << APP_DAC_CTRL_BIAS_Pos)
|
||||||
|
|
||||||
|
static inline uint16_t app_dac_read_reg_ctrl(void);
|
||||||
|
static inline uint16_t app_dac_read_reg_data(void);
|
||||||
|
static inline void app_dac_write_reg_ctrl(uint16_t data);
|
||||||
|
static inline void app_dac_write_reg_data(uint16_t data);
|
||||||
|
|
||||||
|
void app_dac_init(void) {
|
||||||
|
POWER_DisablePD(kPDRUNCFG_PD_DAC0);
|
||||||
|
CLOCK_EnableClock(kCLOCK_Dac);
|
||||||
|
|
||||||
|
RESET_PeripheralReset(kDAC0_RST_N_SHIFT_RSTn);
|
||||||
|
|
||||||
|
DAC0->CR = 0UL;
|
||||||
|
DAC0->CTRL = 0UL;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t app_dac_module_reg_read(uint8_t addr) {
|
||||||
|
uint16_t ret = 0x5555;
|
||||||
|
|
||||||
|
switch (addr) {
|
||||||
|
case APP_DAC_REG_OFFSET_CTRL:
|
||||||
|
ret = app_dac_read_reg_ctrl();
|
||||||
|
break;
|
||||||
|
case APP_DAC_REG_OFFSET_DATA:
|
||||||
|
ret = app_dac_read_reg_data();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_dac_module_reg_write(uint8_t addr, uint16_t data) {
|
||||||
|
switch (addr) {
|
||||||
|
case APP_DAC_REG_OFFSET_CTRL:
|
||||||
|
app_dac_write_reg_ctrl(data);
|
||||||
|
break;
|
||||||
|
case APP_DAC_REG_OFFSET_DATA:
|
||||||
|
app_dac_write_reg_data(data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint16_t app_dac_read_reg_ctrl(void) {
|
||||||
|
uint16_t ret = 0x0000U;
|
||||||
|
|
||||||
|
if (DAC0->CR & DAC_CR_BIAS_MASK) {
|
||||||
|
ret |= APP_DAC_CTRL_BIAS_Msk;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint16_t app_dac_read_reg_data(void) {
|
||||||
|
return ((DAC0->CR & DAC_CR_VALUE_MASK) >> DAC_CR_VALUE_SHIFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void app_dac_write_reg_ctrl(uint16_t data) {
|
||||||
|
if (data & APP_DAC_CTRL_BIAS_Msk) {
|
||||||
|
DAC0->CR |= DAC_CR_BIAS_MASK;
|
||||||
|
} else {
|
||||||
|
DAC0->CR &= ~DAC_CR_BIAS_MASK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void app_dac_write_reg_data(uint16_t data) {
|
||||||
|
uint32_t cr = DAC0->CR;
|
||||||
|
|
||||||
|
cr &= ~DAC_CR_VALUE_MASK;
|
||||||
|
cr |= DAC_CR_VALUE(data);
|
||||||
|
|
||||||
|
DAC0->CR = cr;
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
/* App */
|
/* App */
|
||||||
#include "app_adc.h"
|
#include "app_adc.h"
|
||||||
|
#include "app_dac.h"
|
||||||
#include "app_gpio.h"
|
#include "app_gpio.h"
|
||||||
#include "app_sys_utils.h"
|
#include "app_sys_utils.h"
|
||||||
|
|
||||||
|
@ -9,7 +10,8 @@
|
||||||
#define MODULE_ID_SYS_UTILS 0
|
#define MODULE_ID_SYS_UTILS 0
|
||||||
#define MODULE_ID_GPIO 1
|
#define MODULE_ID_GPIO 1
|
||||||
#define MODULE_ID_ADC 2
|
#define MODULE_ID_ADC 2
|
||||||
#define MODULE_ID_END 3
|
#define MODULE_ID_DAC 3
|
||||||
|
#define MODULE_ID_END 4
|
||||||
|
|
||||||
typedef uint16_t (*module_reg_read_t)(uint8_t offset);
|
typedef uint16_t (*module_reg_read_t)(uint8_t offset);
|
||||||
typedef void (*module_reg_write_t)(uint8_t offset, uint16_t data);
|
typedef void (*module_reg_write_t)(uint8_t offset, uint16_t data);
|
||||||
|
@ -19,7 +21,7 @@ typedef struct {
|
||||||
module_reg_write_t write;
|
module_reg_write_t write;
|
||||||
} module_reg_t;
|
} module_reg_t;
|
||||||
|
|
||||||
static const module_reg_t s_module_regs[] = {
|
static const module_reg_t s_module_regs[MODULE_ID_END] = {
|
||||||
[MODULE_ID_SYS_UTILS] =
|
[MODULE_ID_SYS_UTILS] =
|
||||||
{
|
{
|
||||||
.read = app_sys_utils_module_reg_read,
|
.read = app_sys_utils_module_reg_read,
|
||||||
|
@ -35,6 +37,11 @@ static const module_reg_t s_module_regs[] = {
|
||||||
.read = app_adc_module_reg_read,
|
.read = app_adc_module_reg_read,
|
||||||
.write = app_adc_module_reg_write,
|
.write = app_adc_module_reg_write,
|
||||||
},
|
},
|
||||||
|
[MODULE_ID_DAC] =
|
||||||
|
{
|
||||||
|
.read = app_dac_module_reg_read,
|
||||||
|
.write = app_dac_module_reg_write,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
uint16_t app_reg_if_read(uint8_t reg) {
|
uint16_t app_reg_if_read(uint8_t reg) {
|
||||||
|
|
|
@ -5,16 +5,19 @@
|
||||||
|
|
||||||
/* App */
|
/* App */
|
||||||
#include "app_adc.h"
|
#include "app_adc.h"
|
||||||
|
#include "app_dac.h"
|
||||||
#include "app_gpio.h"
|
#include "app_gpio.h"
|
||||||
#include "app_i2c_if.h"
|
#include "app_i2c_if.h"
|
||||||
#include "app_led.h"
|
#include "app_sys_utils.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
BOARD_InitBootPins();
|
BOARD_InitBootPins();
|
||||||
BOARD_InitBootClocks();
|
BOARD_InitBootClocks();
|
||||||
|
|
||||||
|
app_sys_utils_init();
|
||||||
app_gpio_init();
|
app_gpio_init();
|
||||||
app_adc_init();
|
app_adc_init();
|
||||||
|
app_dac_init();
|
||||||
app_i2c_if_init();
|
app_i2c_if_init();
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user