Compare commits
39 Commits
@ -1,82 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifndef _SPI_CH_H
|
|
||||||
#define _SPI_CH_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "pin.h"
|
|
||||||
#include "spi.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/17052443/c-function-inside-struct
|
|
||||||
typedef uint8_t (*readReg_t) (uint8_t);
|
|
||||||
|
|
||||||
|
|
||||||
/*! \brief SPI cannel class
|
|
||||||
* This class cpntains the pin and spi channel number
|
|
||||||
* select.
|
|
||||||
* */
|
|
||||||
typedef struct{
|
|
||||||
pinNo_t pin, /*!< pin number */
|
|
||||||
spiCH_t spi /*!< spi hardware channel number */
|
|
||||||
}spi_ch_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Read register
|
|
||||||
* Read one byte from a one register with one byte address.
|
|
||||||
* \param *spi_ch spi pointer to spi channel object
|
|
||||||
* \param reg_address register address
|
|
||||||
* \return register content
|
|
||||||
*/
|
|
||||||
uint8_t spiCH_readReg(spi_ch_t *spi_ch,
|
|
||||||
uint8_t reg_address);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Read Block
|
|
||||||
* Read a block of data starting at a given start address.
|
|
||||||
* This function makes use of the auto register increment of the device to be read from.
|
|
||||||
* The address will be sent once and then data is read.
|
|
||||||
* \param *spi_ch pointer to spi cannel object
|
|
||||||
* \param start_address start address to the first register
|
|
||||||
* \param *buffer pointer to the buffer in which the read content is written into
|
|
||||||
* \param buf_len length of buffer
|
|
||||||
*/
|
|
||||||
void spiCH_autoReadBlock(spi_ch_t *spi_ch,
|
|
||||||
uint8_t start_address,
|
|
||||||
uint8_t* buffer,
|
|
||||||
uint8_t buf_len);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Write register
|
|
||||||
* Write one byte to one register with one byte address.
|
|
||||||
* \param *spi_ch pointer to spi channel object
|
|
||||||
* \param reg_address register address
|
|
||||||
* \param data data byte to be written into register
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void spiCH_writeReg(spi_ch_t *spi_ch,
|
|
||||||
uint8_t reg_address,
|
|
||||||
uint8_t data);
|
|
||||||
/**
|
|
||||||
* \brief Write data block
|
|
||||||
* Write a block of data starting at a given start address.
|
|
||||||
* This function makes use of the auto register increment of the device to be written to. The
|
|
||||||
* address will be sent once an then data is written.
|
|
||||||
* \param *spi_ch pointer to spi channel object
|
|
||||||
* \param start_address start address of the first reister
|
|
||||||
* \param *data pointer to data to be written
|
|
||||||
* \param data_len length of data to be written
|
|
||||||
*/
|
|
||||||
void spiCH_writeBlock(spi_ch_t *spi_ch,
|
|
||||||
uint8_t start_address,
|
|
||||||
const uint8_t *data,
|
|
||||||
uint8_t data_len);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif //_SPI_CH_H
|
|
||||||
|
|
@ -0,0 +1,146 @@
|
|||||||
|
#include "spi.h"
|
||||||
|
|
||||||
|
#define SPI_BASE ((SPI_TypeDef *)spiBase_Addr_List[spi_hw_ch])
|
||||||
|
|
||||||
|
void spiReset(spiCH_t spi_hw_ch)
|
||||||
|
{
|
||||||
|
if(spiBus_No[spi_hw_ch] == 1) {
|
||||||
|
RCC->APB1RSTR |= (1 << spiBus_Rst_bitPos[spi_hw_ch]);
|
||||||
|
RCC->APB1RSTR &= ~(1 << spiBus_Rst_bitPos[spi_hw_ch]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RCC->APB2RSTR |= (1 << spiBus_Rst_bitPos[spi_hw_ch]);
|
||||||
|
RCC->APB2RSTR &= ~(1 << spiBus_Rst_bitPos[spi_hw_ch]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiEnableBus(spiCH_t spi_hw_ch)
|
||||||
|
{
|
||||||
|
if(spiBus_No[spi_hw_ch] == 1) {
|
||||||
|
RCC->APB1ENR |= (1 << spiBus_En_bitPos[spi_hw_ch]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RCC->APB2ENR |= (1 << spiBus_En_bitPos[spi_hw_ch]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiEnable(spiCH_t spi_hw_ch)
|
||||||
|
{
|
||||||
|
SPI_BASE->CR1 |= SPI_CR1_SPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiDissable(spiCH_t spi_hw_ch)
|
||||||
|
{
|
||||||
|
// TODO: implement p.768 procedure for dissabling
|
||||||
|
//while(SPI_BASE->SR
|
||||||
|
SPI_BASE->CR1 &= ~SPI_CR1_SPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiSetMode(spiCH_t spi_hw_ch, spi_mode_t mode)
|
||||||
|
{
|
||||||
|
SPI_BASE->CR1 &= ~(mode << SPI_CR1_MSTR_Pos);
|
||||||
|
SPI_BASE->CR1 |= mode << SPI_CR1_MSTR_Pos;
|
||||||
|
|
||||||
|
// TODO: find out if this is the correct place to set the SSOE bit
|
||||||
|
SPI_BASE->CR2 &= ~SPI_CR2_SSOE;
|
||||||
|
if(mode == SPI_MASTER) {
|
||||||
|
SPI_BASE->CR2 |= SPI_CR2_SSOE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiSetPolarity(spiCH_t spi_hw_ch, spi_clkPol_t clkPol)
|
||||||
|
{
|
||||||
|
// reset
|
||||||
|
SPI_BASE->CR1 &= ~SPI_CR1_CPOL;
|
||||||
|
// set
|
||||||
|
SPI_BASE->CR1 |= clkPol << SPI_CR1_CPOL_Pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiSetPhase(spiCH_t spi_hw_ch, spi_phase_t phase)
|
||||||
|
{
|
||||||
|
// reset
|
||||||
|
SPI_BASE->CR1 &= ~(phase << SPI_CR1_CPHA_Pos);
|
||||||
|
// set
|
||||||
|
SPI_BASE->CR1 |= phase << SPI_CR1_CPHA_Pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiSetBitFrameLength(spiCH_t spi_hw_ch, spi_framel_t framel)
|
||||||
|
{
|
||||||
|
|
||||||
|
SPI_BASE->CR2 &= ~(SPI_CR2_FRXTH | SPI_CR2_DS);
|
||||||
|
|
||||||
|
// using p.974 as example
|
||||||
|
if(framel == SPI_FRAME_LENGTH_8BIT) {
|
||||||
|
// set FIFO reception threshold to 8 bit
|
||||||
|
SPI_BASE->CR2 |= SPI_CR2_FRXTH;
|
||||||
|
// set transfer lwnght to 8 bit
|
||||||
|
SPI_BASE->CR2 |= SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SPI_BASE->CR2 |= SPI_CR2_DS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiSetFrameFormat(spiCH_t spi_hw_ch, spi_framef_t framef)
|
||||||
|
{
|
||||||
|
// reset
|
||||||
|
SPI_BASE->CR1 &= ~SPI_CR1_LSBFIRST;
|
||||||
|
// set
|
||||||
|
SPI_BASE->CR1 |= framef << SPI_CR1_LSBFIRST_Pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
spi_framef_t spiGetFrameFormat(spiCH_t spi_hw_ch)
|
||||||
|
{
|
||||||
|
return (spi_framef_t)(SPI_BASE->CR1 & SPI_CR1_LSBFIRST) >> SPI_CR1_LSBFIRST_Pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiSetClockPrescaler(spiCH_t spi_hw_ch, uint32_t clkDiv)
|
||||||
|
{
|
||||||
|
// reset
|
||||||
|
SPI_BASE->CR1 &= ~SPI_CR1_BR;
|
||||||
|
// set
|
||||||
|
SPI_BASE->CR1 |= (clkDiv << SPI_CR1_BR_Pos) & SPI_CR1_BR;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiSetComMode(spiCH_t spi_hw_ch, spi_comMode_t comMode)
|
||||||
|
{
|
||||||
|
// reset
|
||||||
|
SPI_BASE->CR1 &= ~SPI_CR1_RXONLY;
|
||||||
|
// set
|
||||||
|
SPI_BASE->CR1 |= comMode << SPI_CR1_RXONLY_Pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic)
|
||||||
|
{
|
||||||
|
SPI_BASE->CR1 &= ~SPI_CR1_SSM;
|
||||||
|
|
||||||
|
if(logic){
|
||||||
|
SPI_BASE->CR1 |= SPI_CR1_SSM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiSetInternalSlaveSelect(spiCH_t spi_hw_ch, uint8_t logic)
|
||||||
|
{
|
||||||
|
SPI_BASE->CR1 &= ~SPI_CR1_SSI;
|
||||||
|
|
||||||
|
if(logic) {
|
||||||
|
SPI_BASE->CR1 |= SPI_CR1_SSI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t spiTrx8BitPolling(spiCH_t spi_hw_ch, uint8_t tx_data)
|
||||||
|
{
|
||||||
|
// wait for BSY bit to Reset -> This will indicate that SPI is not busy in communication
|
||||||
|
while (SPI_BASE->SR & SPI_SR_BSY);
|
||||||
|
|
||||||
|
// from example code p.975 f
|
||||||
|
// this masking must be done. otherwise 16bits frame will be used
|
||||||
|
*(uint8_t*)&(SPI_BASE->DR) = tx_data;
|
||||||
|
|
||||||
|
// Wait for RXNE to set -> This will indicate that the Rx buffer is not empty
|
||||||
|
while (!(SPI_BASE->SR &SPI_SR_RXNE));
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: test read!
|
||||||
|
return *(uint8_t*)&(SPI_BASE->DR);
|
||||||
|
}
|
||||||
|
|
@ -1,56 +0,0 @@
|
|||||||
#include "spi.h"
|
|
||||||
|
|
||||||
#define SPI_BASE ((SPI_TypeDef *)spiBase_Addr_List[spi_hw_ch])
|
|
||||||
|
|
||||||
// https://controllerstech.com/spi-using-registers-in-stm32/
|
|
||||||
|
|
||||||
void spi_init(spiCH_t spi_hw_ch)
|
|
||||||
{
|
|
||||||
RCC->APB2ENR |= (1<<12); // Enable SPI1 CLock
|
|
||||||
|
|
||||||
SPI1->CR1 |= (1<<0)|(1<<1); // CPOL=1, CPHA=1
|
|
||||||
|
|
||||||
SPI1->CR1 |= (1<<2); // Master Mode
|
|
||||||
|
|
||||||
SPI1->CR1 |= (3<<3); // BR[2:0] = 011: fPCLK/16, PCLK2 = 80MHz, SPI clk = 5MHz
|
|
||||||
|
|
||||||
SPI1->CR1 &= ~(1<<7); // LSBFIRST = 0, MSB first
|
|
||||||
|
|
||||||
SPI1->CR1 |= (1<<8) | (1<<9); // SSM=1, SSi=1 -> Software Slave Management
|
|
||||||
|
|
||||||
SPI1->CR1 &= ~(1<<10); // RXONLY = 0, full-duplex
|
|
||||||
|
|
||||||
SPI1->CR1 &= ~(1<<11); // DFF=0, 8 bit data
|
|
||||||
|
|
||||||
SPI1->CR2 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t spi_trx(spiCH_t spi_hw_ch, uint8_t tx_data)
|
|
||||||
{
|
|
||||||
uint8_t data;
|
|
||||||
// example
|
|
||||||
|
|
||||||
|
|
||||||
while (((SPI1->SR)&(1<<7))); // wait for BSY bit to Reset -> This will indicate that SPI is not busy in communication
|
|
||||||
|
|
||||||
SPI1->DR = tx_data; // send data
|
|
||||||
|
|
||||||
while (!((SPI1->SR) &(1<<0))); // Wait for RXNE to set -> This will indicate that the Rx buffer is not empty
|
|
||||||
data = SPI1->DR;
|
|
||||||
|
|
||||||
return data;
|
|
||||||
|
|
||||||
// implementation 2. step
|
|
||||||
#if 0
|
|
||||||
// wait for SPY ready
|
|
||||||
while((SPI_BASE->SR) & (1 << 7));
|
|
||||||
|
|
||||||
// load tx data
|
|
||||||
SPI_BASE->DR = tx_data;
|
|
||||||
|
|
||||||
// Wait for RXNE flag to be set which indicates transmit complete
|
|
||||||
while(!((SPI_BASE->SR) & (1<<0));
|
|
||||||
|
|
||||||
return SPI_BASE->DR;
|
|
||||||
#endif
|
|
||||||
}
|
|
@ -0,0 +1,2 @@
|
|||||||
|
add_subdirectory(max7219)
|
||||||
|
add_subdirectory(ad9833)
|
@ -0,0 +1,5 @@
|
|||||||
|
add_library(AD9833 ad9833.c)
|
||||||
|
target_compile_options(AD9833 PRIVATE ${C_FLAGS})
|
||||||
|
target_compile_definitions(AD9833 PRIVATE ${C_DEFS})
|
||||||
|
target_include_directories(AD9833 PUBLIC . ${INTERFACES_DIR} ${CSL_INCLUDES})
|
||||||
|
add_library(sub::ad9833 ALIAS AD9833)
|
@ -0,0 +1,107 @@
|
|||||||
|
#include "ad9833.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
_bit_D1 = 0x00,
|
||||||
|
_bit_MODE = 0x0002,
|
||||||
|
_bit_DIV2 = 0x0008,
|
||||||
|
_bit_OPBITEN = 0x0020,
|
||||||
|
_bit_SLEEP12 = 0x0040,
|
||||||
|
_bit_SLEEP1 = 0x0080,
|
||||||
|
_bit_RESET = 0x0100,
|
||||||
|
_bit_PSELECT = 0x0400,
|
||||||
|
_bit_FSELECT = 0x0800,
|
||||||
|
_bit_HLB = 0x1000,
|
||||||
|
_bit_B28 = 0x2000
|
||||||
|
}bit_t;
|
||||||
|
|
||||||
|
void _writeControlRegister(ad9833_t *device, uint16_t entry)
|
||||||
|
{
|
||||||
|
// mask entry to prevent writing to reserved bits
|
||||||
|
spiWrite16bit(device->spiCH, (entry & 0x3DEA));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_init(
|
||||||
|
ad9833_t *device,
|
||||||
|
ad9833_sleepMode_t sleepMode,
|
||||||
|
uint16_t f0,
|
||||||
|
uint16_t f1,
|
||||||
|
uint16_t p0,
|
||||||
|
uint16_t p1)
|
||||||
|
{
|
||||||
|
|
||||||
|
// perform init sequence according to Figure 27.
|
||||||
|
spiWrite16bit(device->spiCH, _bit_RESET);
|
||||||
|
spiWrite16bit(device->spiCH, 0);
|
||||||
|
|
||||||
|
|
||||||
|
// set device directly in full powerdown mode, sinosoidal output
|
||||||
|
device->ctrlReg = _bit_SLEEP1 | _bit_SLEEP12;
|
||||||
|
spiWrite16bit(device->spiCH, device->ctrlReg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_setRefFrequency(
|
||||||
|
ad9833_t *device,
|
||||||
|
float fref)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_reset(
|
||||||
|
ad9833_t *device)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_setSleepMode(
|
||||||
|
ad9833_t *device,
|
||||||
|
ad9833_sleepMode_t sleepMode)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_setOutputSinosoidal(
|
||||||
|
ad9833_t *device)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_setOutputTrangle(
|
||||||
|
ad9833_t *device)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_setOutputMSBofDACData(
|
||||||
|
ad9833_t *device)
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_setFrequency0(
|
||||||
|
ad9833_t *device,
|
||||||
|
uint16_t f0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_setFrequency1(
|
||||||
|
ad9833_t *device,
|
||||||
|
uint16_t f1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_setPhase0(
|
||||||
|
ad9833_t *device,
|
||||||
|
uint32_t p0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_setPhase1(
|
||||||
|
ad9833_t *device,
|
||||||
|
uint32_t p1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,151 @@
|
|||||||
|
#ifndef _AD9833_H_
|
||||||
|
#define _AD9833_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "spi.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
spi_ch_t *spiCH;
|
||||||
|
uint16_t ctrlReg;
|
||||||
|
} ad9833_t;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
INACTIVE = 0x0000,
|
||||||
|
DAC_POWERDOWN = 0x0040,
|
||||||
|
INTERNAL_CLK_DISSABLE = 0x0080,
|
||||||
|
DAC_AND_INT_CLK_DISSABLE = 0x00C0
|
||||||
|
}ad9833_sleepMode_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param device
|
||||||
|
* @param sleepMode
|
||||||
|
*/
|
||||||
|
|
||||||
|
void ad9833_init(
|
||||||
|
ad9833_t *device,
|
||||||
|
ad9833_sleepMode_t sleepMode,
|
||||||
|
uint16_t f0,
|
||||||
|
uint16_t f1,
|
||||||
|
uint16_t p0,
|
||||||
|
uint16_t p1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param device
|
||||||
|
* @param fref
|
||||||
|
*/
|
||||||
|
void ad9833_setRefFrequency(
|
||||||
|
ad9833_t *device,
|
||||||
|
float fref);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reset Device
|
||||||
|
*
|
||||||
|
* The reset function resets appropriate internal registers to 0 to provide an
|
||||||
|
* analog output of midscale. Reset does not reset the phase, frequency, or
|
||||||
|
* control registers. When the AD9833 is powered up, the part should be reset.
|
||||||
|
* To reset the AD9833, set the reset bit to 1. To take the part out of reset,
|
||||||
|
* set the bit to 0. A signal appears at the DAC to output eight MCLK cycles
|
||||||
|
* after reset is set to 0.
|
||||||
|
*
|
||||||
|
* the latter was quoted from datasheet ad9833 Rev.D from Analog Devices
|
||||||
|
* @param device
|
||||||
|
*/
|
||||||
|
void ad9833_reset(
|
||||||
|
ad9833_t *device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set different different sections in powerdown mode
|
||||||
|
*
|
||||||
|
* Different Sections can be put into powerdown to save power.
|
||||||
|
*
|
||||||
|
* The following modes can be set:
|
||||||
|
*
|
||||||
|
* No power-down = INACTIVE
|
||||||
|
* DAC powered down = DAC_POWERDOWN
|
||||||
|
* Internal clock disabled = INTERNAL_CLK_DISSABLE
|
||||||
|
* Both the DAC powered down = DAC_AND_INT_CLK_DISSABLE
|
||||||
|
* and the internal clock disabled
|
||||||
|
* @param device
|
||||||
|
* @param sleepMode
|
||||||
|
*/
|
||||||
|
void ad9833_setSleepMode(
|
||||||
|
ad9833_t *device,
|
||||||
|
ad9833_sleepMode_t sleepMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param device
|
||||||
|
*/
|
||||||
|
void ad9833_setOutputSinosoidal(
|
||||||
|
ad9833_t *device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param device
|
||||||
|
*/
|
||||||
|
void ad9833_setOutputTrangle(
|
||||||
|
ad9833_t *device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param device
|
||||||
|
*/
|
||||||
|
void ad9833_setOutputMSBofDACData(
|
||||||
|
ad9833_t *device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param device
|
||||||
|
* @param f0
|
||||||
|
*/
|
||||||
|
void ad9833_setFrequency0(
|
||||||
|
ad9833_t *device,
|
||||||
|
uint16_t f0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param device
|
||||||
|
* @param f1
|
||||||
|
*/
|
||||||
|
void ad9833_setFrequency1(
|
||||||
|
ad9833_t *device,
|
||||||
|
uint16_t f1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param device
|
||||||
|
* @param p0
|
||||||
|
*/
|
||||||
|
void ad9833_setPhase0(
|
||||||
|
ad9833_t *device,
|
||||||
|
uint32_t p0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param device
|
||||||
|
* @param p1
|
||||||
|
*/
|
||||||
|
void ad9833_setPhase1(
|
||||||
|
ad9833_t *device,
|
||||||
|
uint32_t p1);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _AD9833_H_
|
@ -0,0 +1,5 @@
|
|||||||
|
add_library(MAX7219 max7219.c)
|
||||||
|
target_compile_options(MAX7219 PRIVATE ${C_FLAGS})
|
||||||
|
target_compile_definitions(MAX7219 PRIVATE ${C_DEFS})
|
||||||
|
target_include_directories(MAX7219 PUBLIC . ${INTERFACES_DIR} ${CSL_INCLUDES})
|
||||||
|
add_library(sub::max7219 ALIAS MAX7219)
|
@ -0,0 +1,124 @@
|
|||||||
|
#include "max7219.h"
|
||||||
|
|
||||||
|
void max7219_init(
|
||||||
|
max7219_t *display,
|
||||||
|
spi_ch_t *spi_ch)
|
||||||
|
{
|
||||||
|
display->spiCH = spi_ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_testDisplay(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t logic)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH,0x0F, (logic) ? 0x01 : 0x00);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_shutdownDiaply(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t logic)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH,0x0C, (logic) ? 0x00 : 0x01);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_setDecodeMode(
|
||||||
|
max7219_t *display,
|
||||||
|
max7219_decodeMode_t dmode)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH,0x09,(uint8_t) dmode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_setIntensity(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t intensity)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH, 0x0A, intensity & 0x0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_setScanLimit(
|
||||||
|
max7219_t *display,
|
||||||
|
max7219_scanLimit_t slimit)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH, 0x0B, ((uint8_t) slimit) & 0x0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_setAllLEDsOff(
|
||||||
|
max7219_t *display)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
for(i = 0; i < 9; i++) {
|
||||||
|
spiWriteReg(display->spiCH, i, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_ledMatrixSetLED(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t row,
|
||||||
|
uint8_t col)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t val = 0xAE;
|
||||||
|
|
||||||
|
row = (row & 0x07) + 1;
|
||||||
|
col = 1 << (col & 0x07);
|
||||||
|
|
||||||
|
spiWriteReg(display->spiCH, row,col);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_rawWrite(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t reg,
|
||||||
|
uint8_t data)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH, reg, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_printLedMatrix(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t matrix[])
|
||||||
|
{
|
||||||
|
uint8_t i = 0;
|
||||||
|
|
||||||
|
for(i = 0; i < 8; i ++) {
|
||||||
|
spiWriteReg(display->spiCH, i+1, matrix[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_ledMatrixUnsetLED(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t row,
|
||||||
|
uint8_t col)
|
||||||
|
{
|
||||||
|
row = (row & 0x07) + 1;
|
||||||
|
col = 1 << (col & 0x07);
|
||||||
|
// TODO: find out how to turn off LED
|
||||||
|
spiWriteReg(display->spiCH, row,col+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
// daysichained matrix
|
||||||
|
typedef struct{
|
||||||
|
spi_ch_t *spiCH;
|
||||||
|
uint8_t nDevices;
|
||||||
|
}max7219_dm_t;
|
||||||
|
|
||||||
|
|
||||||
|
void max7219_dm_write(
|
||||||
|
max7219_dm_t *matrix,
|
||||||
|
uint8_t **data)
|
||||||
|
{
|
||||||
|
uint8_t i = 0;
|
||||||
|
uint8_t j = 0;
|
||||||
|
// TODO: Test it out
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
pinWrite(matrix->spiCH->pin, 0);
|
||||||
|
for(j = 0; j < matrix->nDevices; j++) {
|
||||||
|
spiTrx8BitPolling(matrix->spiCH->spi, i+1); // reg
|
||||||
|
spiTrx8BitPolling(matrix->spiCH->spi, data[j][i]);
|
||||||
|
}
|
||||||
|
pinWrite(matrix->spiCH->pin, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,111 @@
|
|||||||
|
/**
|
||||||
|
**************************************************************************************************
|
||||||
|
* @file max7219.h
|
||||||
|
* @author Kerem Yollu & Edwin Koch
|
||||||
|
* @date 25.08.2022
|
||||||
|
* @version 1.0
|
||||||
|
**************************************************************************************************
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* **Detailed Description :**
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
**************************************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MAX7219_H_
|
||||||
|
#define _MAX7219_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "spi.h"
|
||||||
|
#include "pin.h"
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
NO_DECODE_DIGIT_7_TO_0 = 0x00,
|
||||||
|
CODE_B_DECODE_ONLY_DIGIT_0 = 0x01,
|
||||||
|
CODE_B_DECODE_ONLY_DIGIT_3_TO_0 = 0x0F,
|
||||||
|
CODE_B_DECOD_DIGIT_7_TO_0 = 0xFF
|
||||||
|
}max7219_decodeMode_t;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
DISPLAY_DIGIT_0 = 0x00,
|
||||||
|
DISPLAY_DIGIT_1_TO_0 = 0x01,
|
||||||
|
DSIPLAX_DIGIT_2_TO_0 = 0x02,
|
||||||
|
DSIPLAX_DIGIT_3_TO_0 = 0x03,
|
||||||
|
DSIPLAX_DIGIT_4_TO_0 = 0x04,
|
||||||
|
DSIPLAX_DIGIT_5_TO_0 = 0x05,
|
||||||
|
DSIPLAX_DIGIT_6_TO_0 = 0x06,
|
||||||
|
DSIPLAX_DIGIT_7_TO_0 = 0x07
|
||||||
|
}max7219_scanLimit_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
spi_ch_t *spiCH;
|
||||||
|
}max7219_t;
|
||||||
|
|
||||||
|
void max7219_init(
|
||||||
|
max7219_t *display,
|
||||||
|
spi_ch_t *spi_ch);
|
||||||
|
|
||||||
|
void max7219_testDisplay(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t logic);
|
||||||
|
|
||||||
|
void max7219_shutdownDiaply(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t logic);
|
||||||
|
|
||||||
|
void max7219_setDecodeMode(
|
||||||
|
max7219_t *display,
|
||||||
|
max7219_decodeMode_t dmode);
|
||||||
|
|
||||||
|
void max7219_setIntensity(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t intensity);
|
||||||
|
|
||||||
|
void max7219_setScanLimit(
|
||||||
|
max7219_t *display,
|
||||||
|
max7219_scanLimit_t slimit);
|
||||||
|
|
||||||
|
void max7219_setAllLEDsOff(
|
||||||
|
max7219_t *display);
|
||||||
|
|
||||||
|
void max7219_ledMatrixSetLED(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t row,
|
||||||
|
uint8_t col);
|
||||||
|
|
||||||
|
void max7219_rawWrite(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t reg,
|
||||||
|
uint8_t data);
|
||||||
|
|
||||||
|
void max7219_printLedMatrix(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t matrix[]);
|
||||||
|
|
||||||
|
void max7219_ledMatrixUnsetLED(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t row,
|
||||||
|
uint8_t col);
|
||||||
|
#if 0
|
||||||
|
// daysichained matrix
|
||||||
|
typedef struct{
|
||||||
|
spi_ch_t *spiCH;
|
||||||
|
uint8_t nDevices;
|
||||||
|
}max7219_dm_t;
|
||||||
|
|
||||||
|
|
||||||
|
void max7219_dm_write(
|
||||||
|
max7219_dm_t *matrix,
|
||||||
|
uint8_t **data);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _MAX7219_H_
|
@ -0,0 +1,126 @@
|
|||||||
|
#include "max7219.h"
|
||||||
|
|
||||||
|
void max7219_init(
|
||||||
|
max7219_t *display,
|
||||||
|
spi_ch_t *spi_ch)
|
||||||
|
{
|
||||||
|
display->spiCH = spi_ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
void h
|
||||||
|
|
||||||
|
void max7219_testDisplay(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t logic)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH,0x0F, (logic) ? 0x01 : 0x00);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_shutdownDiaply(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t logic)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH,0x0C, (logic) ? 0x00 : 0x01);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_setDecodeMode(
|
||||||
|
max7219_t *display,
|
||||||
|
max7219_decodeMode_t dmode)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH,0x09,(uint8_t) dmode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_setIntensity(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t intensity)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH, 0x0A, intensity & 0x0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_setScanLimit(
|
||||||
|
max7219_t *display,
|
||||||
|
max7219_scanLimit_t slimit)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH, 0x0B, ((uint8_t) slimit) & 0x0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_setAllLEDsOff(
|
||||||
|
max7219_t *display)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
for(i = 0; i < 9; i++) {
|
||||||
|
spiWriteReg(display->spiCH, i, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_ledMatrixSetLED(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t row,
|
||||||
|
uint8_t col)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t val = 0xAE;
|
||||||
|
|
||||||
|
row = (row & 0x07) + 1;
|
||||||
|
col = 1 << (col & 0x07);
|
||||||
|
|
||||||
|
spiWriteReg(display->spiCH, row,col);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_rawWrite(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t reg,
|
||||||
|
uint8_t data)
|
||||||
|
{
|
||||||
|
spiWriteReg(display->spiCH, reg, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_printLedMatrix(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t matrix[])
|
||||||
|
{
|
||||||
|
uint8_t i = 0;
|
||||||
|
|
||||||
|
for(i = 0; i < 8; i ++) {
|
||||||
|
spiWriteReg(display->spiCH, i+1, matrix[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void max7219_ledMatrixUnsetLED(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t row,
|
||||||
|
uint8_t col)
|
||||||
|
{
|
||||||
|
row = (row & 0x07) + 1;
|
||||||
|
col = 1 << (col & 0x07);
|
||||||
|
// TODO: find out how to turn off LED
|
||||||
|
spiWriteReg(display->spiCH, row,col+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
// daysichained matrix
|
||||||
|
typedef struct{
|
||||||
|
spi_ch_t *spiCH;
|
||||||
|
uint8_t nDevices;
|
||||||
|
}max7219_dm_t;
|
||||||
|
|
||||||
|
|
||||||
|
void max7219_dm_write(
|
||||||
|
max7219_dm_t *matrix,
|
||||||
|
uint8_t **data)
|
||||||
|
{
|
||||||
|
uint8_t i = 0;
|
||||||
|
uint8_t j = 0;
|
||||||
|
// TODO: Test it out
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
pinWrite(matrix->spiCH->pin, 0);
|
||||||
|
for(j = 0; j < matrix->nDevices; j++) {
|
||||||
|
spiTrx8BitPolling(matrix->spiCH->spi, i+1); // reg
|
||||||
|
spiTrx8BitPolling(matrix->spiCH->spi, data[j][i]);
|
||||||
|
}
|
||||||
|
pinWrite(matrix->spiCH->pin, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,160 @@
|
|||||||
|
/**
|
||||||
|
**************************************************************************************************
|
||||||
|
* @file max7219.h
|
||||||
|
* @author Kerem Yollu & Edwin Koch
|
||||||
|
* @date 25.08.2022
|
||||||
|
* @version 1.0
|
||||||
|
**************************************************************************************************
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* **Detailed Description :**
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
**************************************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MAX7219_H_
|
||||||
|
#define _MAX7219_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "spi.h"
|
||||||
|
#include "pin.h"
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
NO_DECODE_DIGIT_7_TO_0 = 0x00,
|
||||||
|
CODE_B_DECODE_ONLY_DIGIT_0 = 0x01,
|
||||||
|
CODE_B_DECODE_ONLY_DIGIT_3_TO_0 = 0x0F,
|
||||||
|
CODE_B_DECOD_DIGIT_7_TO_0 = 0xFF
|
||||||
|
}max7219_decodeMode_t;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
DISPLAY_DIGIT_0 = 0x00,
|
||||||
|
DISPLAY_DIGIT_1_TO_0 = 0x01,
|
||||||
|
DSIPLAX_DIGIT_2_TO_0 = 0x02,
|
||||||
|
DSIPLAX_DIGIT_3_TO_0 = 0x03,
|
||||||
|
DSIPLAX_DIGIT_4_TO_0 = 0x04,
|
||||||
|
DSIPLAX_DIGIT_5_TO_0 = 0x05,
|
||||||
|
DSIPLAX_DIGIT_6_TO_0 = 0x06,
|
||||||
|
DSIPLAX_DIGIT_7_TO_0 = 0x07
|
||||||
|
}max7219_scanLimit_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief max7219 matrix class
|
||||||
|
*
|
||||||
|
* The matrix can be ccomposed of only one ore many devices daysichained
|
||||||
|
* together.
|
||||||
|
* @var *spiCH Pointer to spi channel object
|
||||||
|
* @var nDevicesChained Ammount of devices hoocked up together
|
||||||
|
* @var brightness brightness of the matrix
|
||||||
|
* @var buf Array of matrix content. Each n to n + 7 (n can be 0, 8, 16, etc) represents the
|
||||||
|
* content of one individual max7219 device.
|
||||||
|
*/
|
||||||
|
typedef struct{
|
||||||
|
spi_ch_t *spiCH;
|
||||||
|
uint8_t nDevicesChained;
|
||||||
|
uint8_t brightness;
|
||||||
|
uint8_t buf[];
|
||||||
|
}max7219_mx_t;
|
||||||
|
|
||||||
|
void max7219_t_mx_init(
|
||||||
|
max7219_mx_t *matrix,
|
||||||
|
spi_ch_t *spiChannel,
|
||||||
|
uint8_t *pBuf,
|
||||||
|
uint8_t bufLen);
|
||||||
|
|
||||||
|
void max7219_mx_setPixel(
|
||||||
|
max7219_mx_t *matrix,
|
||||||
|
uint8_t row,
|
||||||
|
uint8_t col,
|
||||||
|
uint8_t logic);
|
||||||
|
|
||||||
|
void max7219_mx_print(
|
||||||
|
max7219_mx_t *matrix,
|
||||||
|
char *text,
|
||||||
|
uint8_t len);
|
||||||
|
|
||||||
|
void max7219_mx_show(
|
||||||
|
max7219_mx_t *matrix);
|
||||||
|
|
||||||
|
void max7219_mx_shutdown(
|
||||||
|
max7219_mx_t *matrix);
|
||||||
|
|
||||||
|
void max7219_mx_test(
|
||||||
|
max7219_mx_t *matrix);
|
||||||
|
|
||||||
|
void max7219_mx_mapMatrix(
|
||||||
|
max7219_mx_t *matrix,
|
||||||
|
uint8_t *map);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
void max7219_init(
|
||||||
|
max7219_t *display,
|
||||||
|
spi_ch_t *spi_ch);
|
||||||
|
|
||||||
|
void max7219_testDisplay(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t logic);
|
||||||
|
|
||||||
|
void max7219_shutdownDiaply(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t logic);
|
||||||
|
|
||||||
|
void max7219_setDecodeMode(
|
||||||
|
max7219_t *display,
|
||||||
|
max7219_decodeMode_t dmode);
|
||||||
|
|
||||||
|
void max7219_setIntensity(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t intensity);
|
||||||
|
|
||||||
|
void max7219_setScanLimit(
|
||||||
|
max7219_t *display,
|
||||||
|
max7219_scanLimit_t slimit);
|
||||||
|
|
||||||
|
void max7219_setAllLEDsOff(
|
||||||
|
max7219_t *display);
|
||||||
|
|
||||||
|
void max7219_ledMatrixSetLED(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t row,
|
||||||
|
uint8_t col);
|
||||||
|
|
||||||
|
void max7219_rawWrite(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t reg,
|
||||||
|
uint8_t data);
|
||||||
|
|
||||||
|
void max7219_printLedMatrix(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t matrix[]);
|
||||||
|
|
||||||
|
void max7219_ledMatrixUnsetLED(
|
||||||
|
max7219_t *display,
|
||||||
|
uint8_t row,
|
||||||
|
uint8_t col);
|
||||||
|
#if 0
|
||||||
|
// daysichained matrix
|
||||||
|
typedef struct{
|
||||||
|
spi_ch_t *spiCH;
|
||||||
|
uint8_t nDevices;
|
||||||
|
}max7219_dm_t;
|
||||||
|
|
||||||
|
|
||||||
|
void max7219_dm_write(
|
||||||
|
max7219_dm_t *matrix,
|
||||||
|
uint8_t **data);
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
#ifdef _cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _MAX7219_H_
|
@ -1 +1,5 @@
|
|||||||
# add_subdirectory(${CSL_USED})
|
add_library(SPI spi.c)
|
||||||
|
target_compile_options(SPI PRIVATE ${C_FLAGS})
|
||||||
|
target_compile_definitions(SPI PRIVATE ${C_DEFS})
|
||||||
|
target_include_directories(SPI PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES})
|
||||||
|
add_library(sub::spi ALIAS SPI)
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
add_library(ledDriver led.cpp)
|
|
||||||
|
|
||||||
target_compile_options(ledDriver PRIVATE ${C_FLAGS})
|
|
||||||
target_compile_definitions(ledDriver PRIVATE ${C_DEFS})
|
|
||||||
target_include_directories(ledDriver PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
|
||||||
|
|
||||||
add_library(sub::led ALIAS ledDriver)
|
|
@ -1,30 +0,0 @@
|
|||||||
#include "led.hpp"
|
|
||||||
|
|
||||||
Led::Led(Pin* pin_ptr)
|
|
||||||
{
|
|
||||||
pin = pin_ptr;
|
|
||||||
pin->init();
|
|
||||||
pin->setMode(Pin::mode::output);
|
|
||||||
pin->setSpeed(Pin::speed::fast);
|
|
||||||
}
|
|
||||||
|
|
||||||
Led::~Led()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Led::on()
|
|
||||||
{
|
|
||||||
pin->write(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Led::off()
|
|
||||||
{
|
|
||||||
pin->write(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Led::toggle()
|
|
||||||
{
|
|
||||||
pin->toggle();
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
|||||||
#ifndef _LED_HPP
|
|
||||||
#define _LED_HPP
|
|
||||||
|
|
||||||
|
|
||||||
class Led
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Led(Pin *pin_ptr);
|
|
||||||
~Led();
|
|
||||||
|
|
||||||
void on();
|
|
||||||
void off();
|
|
||||||
void toggle();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Pin *pin;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __LED_HPP */
|
|
@ -0,0 +1,219 @@
|
|||||||
|
#include "spi.h"
|
||||||
|
|
||||||
|
// generic implementation of spi channel class
|
||||||
|
|
||||||
|
void spiInitMaster(
|
||||||
|
spiCH_t spi_hw_ch,
|
||||||
|
spi_clkPol_t clockPolarity,
|
||||||
|
spi_phase_t phase,
|
||||||
|
spi_framef_t frameFormat,
|
||||||
|
spi_comMode_t comMode,
|
||||||
|
uint32_t prescaler,
|
||||||
|
pinNo_t clkPin,
|
||||||
|
uint16_t altFuncClkPin,
|
||||||
|
pinNo_t MOSIPin,
|
||||||
|
uint16_t altFuncMOSIPin,
|
||||||
|
pinNo_t MISOPin,
|
||||||
|
uint16_t altFuncMISOPin)
|
||||||
|
{
|
||||||
|
// GPIO setup
|
||||||
|
pinInit(clkPin);
|
||||||
|
pinInit(MOSIPin);
|
||||||
|
pinInit(MISOPin);
|
||||||
|
pinConfig(clkPin, alternate, pushPull, output, veryFast);
|
||||||
|
pinConfig(MISOPin, alternate, floating, input , veryFast);
|
||||||
|
pinConfig(MOSIPin, alternate, pushPull, output, veryFast);
|
||||||
|
pinSetAlternate(clkPin, altFuncClkPin);
|
||||||
|
pinSetAlternate(MOSIPin, altFuncMOSIPin);
|
||||||
|
pinSetAlternate(MISOPin, altFuncMISOPin);
|
||||||
|
|
||||||
|
// SPI setup
|
||||||
|
spiEnableBus(spi_hw_ch);
|
||||||
|
spiSetPolarity(spi_hw_ch,clockPolarity);
|
||||||
|
spiSetPhase(spi_hw_ch,phase);
|
||||||
|
spiSetMode(spi_hw_ch, SPI_MASTER);
|
||||||
|
spiSetClockPrescaler(spi_hw_ch, prescaler);
|
||||||
|
spiSetFrameFormat(spi_hw_ch,frameFormat);
|
||||||
|
spiSetSoftwareSlaveManagement(spi_hw_ch,1);
|
||||||
|
spiSetInternalSlaveSelect(spi_hw_ch,0);
|
||||||
|
spiSetComMode(spi_hw_ch, comMode);
|
||||||
|
spiSetClockPrescaler(spi_hw_ch, prescaler);
|
||||||
|
spiSetBitFrameLength(spi_hw_ch, SPI_FRAME_LENGTH_8BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiSetupCH(spi_ch_t *ch, spiCH_t spi_hw_ch, pinNo_t chipselectPin)
|
||||||
|
{
|
||||||
|
ch->pin = chipselectPin;
|
||||||
|
ch->spi = spi_hw_ch;
|
||||||
|
pinWrite(chipselectPin, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t spiReadReg(spi_ch_t *spi_ch, uint8_t reg_address) {
|
||||||
|
uint8_t buf;
|
||||||
|
|
||||||
|
// select target device
|
||||||
|
pinWrite(spi_ch->pin,0);
|
||||||
|
|
||||||
|
// send address of target register
|
||||||
|
spiTrx8BitPolling(spi_ch->spi, reg_address);
|
||||||
|
|
||||||
|
// read from target register
|
||||||
|
buf = spiTrx8BitPolling(spi_ch->spi,0x00);
|
||||||
|
|
||||||
|
// release target device
|
||||||
|
pinWrite(spi_ch->pin,1);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiAutoReadBlock(spi_ch_t *spi_ch,
|
||||||
|
uint8_t start_address,
|
||||||
|
uint8_t* buffer,
|
||||||
|
uint8_t buf_len) {
|
||||||
|
uint8_t i = 0;
|
||||||
|
|
||||||
|
// select target device
|
||||||
|
pinWrite(spi_ch->pin,0);
|
||||||
|
|
||||||
|
// send address of starting register
|
||||||
|
spiTrx8BitPolling(spi_ch->spi, start_address);
|
||||||
|
|
||||||
|
// read block from device
|
||||||
|
for(;i < buf_len;i++) {
|
||||||
|
buffer[i] = spiTrx8BitPolling(spi_ch->spi, 0x00);
|
||||||
|
}
|
||||||
|
|
||||||
|
// release target device
|
||||||
|
pinWrite(spi_ch->pin,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiWriteReg(spi_ch_t *spi_ch,
|
||||||
|
uint8_t reg_address,
|
||||||
|
uint8_t data) {
|
||||||
|
// select target device
|
||||||
|
pinWrite(spi_ch->pin,0);
|
||||||
|
|
||||||
|
// send address of target register
|
||||||
|
spiTrx8BitPolling(spi_ch->spi, reg_address);
|
||||||
|
|
||||||
|
// write to target register
|
||||||
|
spiTrx8BitPolling(spi_ch->spi, data);
|
||||||
|
|
||||||
|
// release target device
|
||||||
|
pinWrite(spi_ch->pin,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiWriteBlock(spi_ch_t *spi_ch,
|
||||||
|
uint8_t start_address,
|
||||||
|
const uint8_t *data,
|
||||||
|
uint8_t data_len) {
|
||||||
|
uint8_t i = 0;
|
||||||
|
|
||||||
|
// select target device
|
||||||
|
pinWrite(spi_ch->pin,0);
|
||||||
|
|
||||||
|
// send address of starting register
|
||||||
|
spiTrx8BitPolling(spi_ch->spi, start_address);
|
||||||
|
|
||||||
|
// read block from device
|
||||||
|
for(;i < data_len;i++) {
|
||||||
|
spiTrx8BitPolling(spi_ch->spi, data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// release target device
|
||||||
|
pinWrite(spi_ch->pin,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiWrite8bit(spi_ch_t *spi_ch,
|
||||||
|
uint8_t bits)
|
||||||
|
{
|
||||||
|
pinWrite(spi_ch->pin,0);
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,bits);
|
||||||
|
pinWrite(spi_ch->pin,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t spiReadWrite8bit(spi_ch_t *spi_ch,
|
||||||
|
uint8_t bits)
|
||||||
|
{
|
||||||
|
uint8_t buf;
|
||||||
|
pinWrite(spi_ch->pin,0);
|
||||||
|
buf = spiTrx8BitPolling(spi_ch->spi,bits);
|
||||||
|
pinWrite(spi_ch->pin,1);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiWrite16bit(spi_ch_t *spi_ch,
|
||||||
|
uint16_t bits)
|
||||||
|
{
|
||||||
|
pinWrite(spi_ch->pin,0);
|
||||||
|
if(spiGetFrameFormat(spi_ch->spi) == SPI_MSB_FIRST) {
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 8));
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits));
|
||||||
|
} else {
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits));
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 8));
|
||||||
|
}
|
||||||
|
pinWrite(spi_ch->pin,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t spiReadWrite16bit(spi_ch_t *spi_ch,
|
||||||
|
uint16_t bits)
|
||||||
|
{
|
||||||
|
uint16_t buf;
|
||||||
|
|
||||||
|
pinWrite(spi_ch->pin,0);
|
||||||
|
if(spiGetFrameFormat(spi_ch->spi) == SPI_LSB_FIRST) {
|
||||||
|
buf = spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 8)) << 8;
|
||||||
|
buf |= spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits));
|
||||||
|
} else {
|
||||||
|
buf = spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits));
|
||||||
|
buf |= spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 8)) << 8;
|
||||||
|
}
|
||||||
|
pinWrite(spi_ch->pin,1);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spiWrite32bit(spi_ch_t *spi_ch,
|
||||||
|
uint32_t bits)
|
||||||
|
{
|
||||||
|
pinWrite(spi_ch->pin,0);
|
||||||
|
|
||||||
|
if(spiGetFrameFormat(spi_ch->spi) == SPI_LSB_FIRST) {
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 24));
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 16));
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 8));
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits));
|
||||||
|
} else {
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits));
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 8));
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 16));
|
||||||
|
spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 24));
|
||||||
|
}
|
||||||
|
pinWrite(spi_ch->pin,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t spiReadWrite32bit(spi_ch_t *spi_ch,
|
||||||
|
uint8_t bits)
|
||||||
|
{
|
||||||
|
uint32_t buf;
|
||||||
|
|
||||||
|
pinWrite(spi_ch->pin,0);
|
||||||
|
if(spiGetFrameFormat(spi_ch->spi) == SPI_LSB_FIRST) {
|
||||||
|
buf = spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 24)) << 24;
|
||||||
|
buf |= spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 16)) << 16;
|
||||||
|
buf |= spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 8)) << 8;
|
||||||
|
buf |= spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits));
|
||||||
|
} else {
|
||||||
|
buf = spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits));
|
||||||
|
buf |= spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 8)) >> 8;
|
||||||
|
buf |= spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 16)) >> 16;
|
||||||
|
buf |= spiTrx8BitPolling(spi_ch->spi,(uint8_t)(bits >> 24)) >> 24;
|
||||||
|
}
|
||||||
|
pinWrite(spi_ch->pin,1);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
|||||||
#include "spi_ch.h"
|
|
||||||
|
|
||||||
// generic implementation of spi channel class
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t spiCH_readReg(spi_ch_t *spi_ch,
|
|
||||||
uint8_t reg_address) {
|
|
||||||
uitn8_t buf;
|
|
||||||
|
|
||||||
// select target device
|
|
||||||
pinWrite(spi_ch->pin,0);
|
|
||||||
|
|
||||||
// send address of target register
|
|
||||||
spi_trx(spi_ch->spi, reg_address);
|
|
||||||
|
|
||||||
// read from target register
|
|
||||||
buf = spi_trx(spi->spi,0x00);
|
|
||||||
|
|
||||||
// release target device
|
|
||||||
pinWrite(spi_ch->pin,1);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
void spiCH_autoReadBlock(spi_ch_t *spi_ch,
|
|
||||||
uint8_t start_address,
|
|
||||||
uint8_t* buffer,
|
|
||||||
uint8_t buf_len) {
|
|
||||||
uint8_t i = 0;
|
|
||||||
|
|
||||||
// select target device
|
|
||||||
pinWrite(spi_ch->pin,0);
|
|
||||||
|
|
||||||
// send address of starting register
|
|
||||||
spi_trx(spi_ch->spi, reg_address);
|
|
||||||
|
|
||||||
// read block from device
|
|
||||||
for(;i < buf_len;i++) {
|
|
||||||
buffer[i] = spi_trx(spi_ch->spi, 0x00);
|
|
||||||
}
|
|
||||||
|
|
||||||
// release target device
|
|
||||||
pinWrite(spi_ch->pin,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void spiCH_writeReg(spi_ch_t *spi_ch,
|
|
||||||
uint8_t reg_address,
|
|
||||||
uint8_t data) {
|
|
||||||
// select target device
|
|
||||||
pinWrite(spi_ch->pin,0);
|
|
||||||
|
|
||||||
// send address of target register
|
|
||||||
spi_trx(spi_ch->spi, reg_address);
|
|
||||||
|
|
||||||
// write to target register
|
|
||||||
spi_trx(spi->spi, data);
|
|
||||||
|
|
||||||
// release target device
|
|
||||||
pinWrite(spi_ch->pin,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void spiCH_writeBlock(spi_ch_t *spi_ch,
|
|
||||||
uint8_t start_address,
|
|
||||||
const uint8_t *data,
|
|
||||||
uint8_t data_len) {
|
|
||||||
uint8_t i = 0;
|
|
||||||
|
|
||||||
// select target device
|
|
||||||
pinWrite(spi_ch->pin,0);
|
|
||||||
|
|
||||||
// send address of starting register
|
|
||||||
spi_trx(spi_ch->spi, reg_address);
|
|
||||||
|
|
||||||
// read block from device
|
|
||||||
for(;i < buf_len;i++) {
|
|
||||||
spi_trx(spi_ch->spi, data[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// release target device
|
|
||||||
pinWrite(spi_ch->pin,1);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in new issue