[refactor] prepare for link gen
This commit is contained in:
@@ -9,12 +9,14 @@
|
||||
|
||||
void ad9833_spi_activate(ad9833_handle_t *hfg)
|
||||
{
|
||||
HAL_GPIO_WritePin(hfg->cs_port, hfg->cs_pin, GPIO_PIN_RESET);
|
||||
// HAL_GPIO_WritePin(hfg->cs_port, hfg->cs_pin, GPIO_PIN_RESET);
|
||||
hfg->hcs->cs_on(hfg->hcs);
|
||||
}
|
||||
|
||||
void ad9833_spi_deactivate(ad9833_handle_t *hfg)
|
||||
{
|
||||
HAL_GPIO_WritePin(hfg->cs_port, hfg->cs_pin, GPIO_PIN_SET);
|
||||
// HAL_GPIO_WritePin(hfg->cs_port, hfg->cs_pin, GPIO_PIN_SET);
|
||||
hfg->hcs->cs_off(hfg->hcs);
|
||||
}
|
||||
|
||||
static void ad9833_transmit16(ad9833_handle_t *hfg, uint16_t data)
|
||||
@@ -41,16 +43,15 @@ void ad9833_reset(ad9833_handle_t *hfg, uint8_t hold)
|
||||
}
|
||||
}
|
||||
|
||||
void ad9833_init(ad9833_handle_t *hfg, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin)
|
||||
void ad9833_init(ad9833_handle_t *hfg, SPI_HandleTypeDef *hspi, cs_handle_t *hcs)
|
||||
// Initialise the AD9833 and then set up safe values for the AD9833 device
|
||||
// Procedure from Figure 27 of in the AD9833 Data Sheet
|
||||
{
|
||||
// initialise our preferred CS pin (could be same as SS)
|
||||
hfg->hspi = hspi;
|
||||
hfg->cs_port = cs_port;
|
||||
hfg->cs_pin = cs_pin;
|
||||
hfg->hcs = hcs;
|
||||
|
||||
HAL_GPIO_WritePin(hfg->cs_port, hfg->cs_pin, GPIO_PIN_SET);
|
||||
hfg->hcs->cs_off(hfg->hcs);
|
||||
|
||||
hfg->_regCtl = 0;
|
||||
hfg->_regCtl |= (1 << AD_B28); // always write 2 words consecutively for frequency
|
||||
@@ -181,8 +182,6 @@ void ad9833_setFrequency(ad9833_handle_t *hfg, AD_channel_t chan, uint32_t freq)
|
||||
// PRINT("\nsetFreq CHAN_", chan);
|
||||
uint16_t freq_channel = 0;
|
||||
|
||||
hfg->_freq[chan] = freq;
|
||||
|
||||
hfg->_regFreq[chan] = ad9833_calcFreq_uint(freq);
|
||||
|
||||
// select the address mask
|
||||
@@ -215,7 +214,6 @@ void ad9833_setPhase(ad9833_handle_t *hfg, AD_channel_t chan, uint16_t phase)
|
||||
// PRINT("\nsetPhase CHAN_", chan);
|
||||
uint16_t phase_channel = 0;
|
||||
|
||||
hfg->_phase[chan] = phase;
|
||||
hfg->_regPhase[chan] = ad9833_calcPhase_uint(phase);
|
||||
|
||||
// select the address mask
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spi_cs_if.h"
|
||||
|
||||
#define AD_DEFAULT_FREQ 1000U ///< Default initialisation frequency (Hz)
|
||||
#define AD_DEFAULT_PHASE 0 ///< Default initialisation phase angle (degrees)
|
||||
#define AD_MCLK 25000000U ///< Clock speed of the AD9833 reference clock in Hz
|
||||
@@ -37,16 +39,13 @@ typedef struct
|
||||
uint32_t _regFreq[2]; // frequency registers
|
||||
uint32_t _regPhase[2]; // phase registers
|
||||
|
||||
AD_mode_t _mode; // last set mode
|
||||
float _freq[2]; // last frequencies set
|
||||
uint16_t _phase[2]; // last phase setting
|
||||
AD_mode_t _mode; // last set mode
|
||||
|
||||
SPI_HandleTypeDef *hspi;
|
||||
GPIO_TypeDef *cs_port;
|
||||
uint16_t cs_pin;
|
||||
cs_handle_t *hcs;
|
||||
} ad9833_handle_t;
|
||||
|
||||
void ad9833_init(ad9833_handle_t *hfg, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin);
|
||||
void ad9833_init(ad9833_handle_t *hfg, SPI_HandleTypeDef *hspi, cs_handle_t *hcs);
|
||||
void ad9833_spi_activate(ad9833_handle_t *hfg);
|
||||
void ad9833_spi_deactivate(ad9833_handle_t *hfg);
|
||||
void ad9833_reset(ad9833_handle_t *hfg, uint8_t hold);
|
||||
|
||||
19
firmware/shared_libs/drivers/led/led.c
Normal file
19
firmware/shared_libs/drivers/led/led.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "led.h"
|
||||
|
||||
void led_init(led_handle_t *hled, GPIO_TypeDef *port, uint16_t pin)
|
||||
{
|
||||
hled->port = port;
|
||||
hled->pin = pin;
|
||||
|
||||
HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
void led_on(led_handle_t *hled)
|
||||
{
|
||||
HAL_GPIO_WritePin(hled->port, hled->pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void led_off(led_handle_t *hled)
|
||||
{
|
||||
HAL_GPIO_WritePin(hled->port, hled->pin, GPIO_PIN_SET);
|
||||
}
|
||||
8
firmware/shared_libs/drivers/led/led.h
Normal file
8
firmware/shared_libs/drivers/led/led.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "gpio.h"
|
||||
#include "ctrl_app_types.h"
|
||||
|
||||
void led_init(led_handle_t *hled, GPIO_TypeDef *port, uint16_t pin);
|
||||
void led_on(led_handle_t *hled);
|
||||
void led_off(led_handle_t *hled);
|
||||
@@ -5,20 +5,19 @@ static uint32_t pot_value[MCP41X_RES_MAX] = {10000, 50000, 100000};
|
||||
|
||||
static void mcp41x_transmit(mcp41x_handle_t *hpot, uint8_t *data)
|
||||
{
|
||||
HAL_GPIO_WritePin(hpot->cs_port, hpot->cs_pin, GPIO_PIN_RESET);
|
||||
hpot->hcs->cs_on(hpot->hcs);
|
||||
HAL_SPI_Transmit(hpot->hspi, data, 2, HAL_MAX_DELAY);
|
||||
HAL_GPIO_WritePin(hpot->cs_port, hpot->cs_pin, GPIO_PIN_SET);
|
||||
hpot->hcs->cs_off(hpot->hcs);
|
||||
}
|
||||
|
||||
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin, mcp41x_res_t res)
|
||||
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, cs_handle_t *hcs, mcp41x_res_t res)
|
||||
{
|
||||
hpot->hspi = hspi;
|
||||
hpot->cs_port = cs_port;
|
||||
hpot->cs_pin = cs_pin;
|
||||
hpot->hcs = hcs;
|
||||
hpot->max_res = res;
|
||||
hpot->dir = MCP41X_ATOB;
|
||||
|
||||
HAL_GPIO_WritePin(hpot->cs_port, hpot->cs_pin, GPIO_PIN_SET);
|
||||
hpot->hcs->cs_off(hcs);
|
||||
}
|
||||
|
||||
void mcp41x_setValue(mcp41x_handle_t *hpot, uint8_t value)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spi_cs_if.h"
|
||||
|
||||
#define MCP41X_C1 5
|
||||
#define MCP41X_C0 4
|
||||
#define MCP41X_P1 1
|
||||
@@ -36,11 +38,10 @@ typedef struct
|
||||
uint8_t value;
|
||||
|
||||
SPI_HandleTypeDef *hspi;
|
||||
GPIO_TypeDef *cs_port;
|
||||
uint16_t cs_pin;
|
||||
cs_handle_t *hcs;
|
||||
} mcp41x_handle_t;
|
||||
|
||||
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin, mcp41x_res_t res);
|
||||
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, cs_handle_t *hcs, mcp41x_res_t res);
|
||||
void mcp41x_setValue(mcp41x_handle_t *hpot, uint8_t value);
|
||||
void mcp41x_setVolume(mcp41x_handle_t *hpot, uint8_t volume);
|
||||
uint8_t mcp41x_getVolume(mcp41x_handle_t *hpot);
|
||||
|
||||
24
firmware/shared_libs/drivers/mcu_cs/mcu_cs.c
Normal file
24
firmware/shared_libs/drivers/mcu_cs/mcu_cs.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "mcu_cs.h"
|
||||
|
||||
// static cs_handle_t const _cs_handle = {.cs_on = mcu_cs_on, .cs_off = mcu_cs_off};
|
||||
|
||||
void mcu_cs_init(MCU_cs_t *hcs, GPIO_TypeDef *cs_port, uint16_t cs_pin, uint8_t cs_idle)
|
||||
{
|
||||
hcs->super.cs_on = mcu_cs_on;
|
||||
hcs->super.cs_off = mcu_cs_off;
|
||||
hcs->cs_port = cs_port;
|
||||
hcs->cs_pin = cs_pin;
|
||||
hcs->cs_idle = cs_idle;
|
||||
}
|
||||
|
||||
void mcu_cs_on(cs_handle_t *hcs)
|
||||
{
|
||||
MCU_cs_t *_hcs = (MCU_cs_t *)hcs;
|
||||
HAL_GPIO_WritePin(_hcs->cs_port, _hcs->cs_pin, !_hcs->cs_idle);
|
||||
}
|
||||
|
||||
void mcu_cs_off(cs_handle_t *hcs)
|
||||
{
|
||||
MCU_cs_t *_hcs = (MCU_cs_t *)hcs;
|
||||
HAL_GPIO_WritePin(_hcs->cs_port, _hcs->cs_pin, _hcs->cs_idle);
|
||||
}
|
||||
16
firmware/shared_libs/drivers/mcu_cs/mcu_cs.h
Normal file
16
firmware/shared_libs/drivers/mcu_cs/mcu_cs.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "main.h"
|
||||
#include "spi_cs_if.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cs_handle_t super;
|
||||
GPIO_TypeDef *cs_port;
|
||||
uint16_t cs_pin;
|
||||
uint8_t cs_idle;
|
||||
} MCU_cs_t;
|
||||
|
||||
void mcu_cs_init(MCU_cs_t *hcs, GPIO_TypeDef *cs_port, uint16_t cs_pin, uint8_t cs_idle);
|
||||
void mcu_cs_on(cs_handle_t *me);
|
||||
void mcu_cs_off(cs_handle_t *me);
|
||||
Reference in New Issue
Block a user