Compare commits

...

39 Commits

Author SHA1 Message Date
Kerem Yollu f11a947038 Edwin check the _
3 years ago
polymurph f3d39226db working on implementing ad9833 into cmake + solving errors
3 years ago
polymurph d9cac30812 added .c/.h files
3 years ago
kerem e08417795a 2 Issues found 1st you need to include the sub::imp_spi on the config.cmake 2nd in config.cmake sub::pin should be compiled after the spi.c as you are using pin funtion directi on spi.c Now compiling ;)
3 years ago
Kerem Yollu 2429425b9e Found the header but genrater new errors, i dind't touch one line of code only eddited the cmakes
3 years ago
polymurph 24acc2e5a1 trying to add the device driver max7219 to cmake
3 years ago
polymurph 7d19fb79c7 working on implementing device_drivers directory into cmake
3 years ago
polymurph 6842f8a6c1 working on new implementation of the max7219
3 years ago
polymurph c3096dfd23 moving max7219 stuff from main into device drivers folder. Cmake stuff is not yet implemented! This needs to be done sothat one can include it like so #include max7219.h
3 years ago
polymurph 76fc103c14 removed hardware dependent stuff from spi.h and spi.c and moved it into imp_spi.c
3 years ago
polymurph c56587c873 implemented auto pinsetup in spiInitMaster
3 years ago
polymurph 984f8c8677 working on multi led matrix driver
3 years ago
polymurph abe86e7192 created a matrix print function
3 years ago
polymurph ec3fad9a7b trying to unset LED... not jet woring
3 years ago
polymurph 7b457d4643 working example with max7219. all max7219 stuff was done insidne main. must be put into device drivers in the futer + cmake must be adapted for this
3 years ago
polymurph 978ca001eb working on driver for the max7219 to test the spi interface. Problem remains with the integration of the device drivers inside the cmake project
3 years ago
polymurph 78ce1a0ec4 working on master init fuction
3 years ago
polymurph f22ef7450b changed chipslect pin
3 years ago
polymurph cde2895fff cleanup + work on frame lenght
3 years ago
polymurph 0b46bcc24a cleanup + work on implementation
3 years ago
polymurph fa69bbdc87 started work on implementation of missing features
3 years ago
polymurph 6214d67393 working better example of alternating On Off Frame test with MAX7219
3 years ago
polymurph 734647f637 working crude example
3 years ago
polymurph f678c41563 working on init function
3 years ago
polymurph bcff2e2cc0 working example.now step by step make init function generic
3 years ago
polymurph 411403e946 working on init function
3 years ago
polymurph d28e42f2c1 added new functions to spi
3 years ago
polymurph 124ad69802 code error solving and cleanup
3 years ago
polymurph 34ef9bf307 new structure wth driver folder for all the generic code
3 years ago
polymurph 2962ebd6e3 setup example with spi CH. Problem with linking still not solved
3 years ago
polymurph 60a9a2cf6c added clear at the begining of the run script
3 years ago
polymurph ed491a7aaf working on implementing spiCH
3 years ago
polymurph 3ebf3744f3 resolved small errors
3 years ago
polymurph 731af596ae small change to tmux bash script
3 years ago
polymurph 64e5259fca work on interface and implementation of spi
3 years ago
polymurph 8d8922c0e9 working on spi init function
3 years ago
polymurph 7ec3ddc352 work on spi interface
3 years ago
polymurph 410687eebf working spi example. Pins(NUCLEO): CLK -> A6, MOSI -> A6 and MISO -> A5
3 years ago
polymurph e6698f1eea working spi example. Pins(NUCLEO): CLK -> A6, MOSI -> A6 and MISO -> A5
3 years ago

@ -24,7 +24,8 @@ set(EXECUTABLE ${PROJECT_NAME}) #Create the executable
#################################################################################################### ####################################################################################################
set(INTERFACES_DIR ${CMAKE_SOURCE_DIR}/csl/interfaces) set(INTERFACES_DIR ${CMAKE_SOURCE_DIR}/csl/interfaces)
set(UTILS_DIR ${CMAKE_SOURCE_DIR}/utils/assert) set(UTILS_DIR ${CMAKE_SOURCE_DIR}/utils/assert)
set(DRIVERS_DIR ${CMAKE_DRIVERS_DIR}/drivers) set(DRIVERS_DIR ${CMAKE_SOURCE_DIR}/drivers)
set(DEVICE_DRIVERS_DIR ${CMAKE_SOURCE_DIR}/device_drivers)
#################################################################################################### ####################################################################################################
#SUBDIRECTORIES Will add the given folders to the porject an check for CmakeLists.txt #SUBDIRECTORIES Will add the given folders to the porject an check for CmakeLists.txt
@ -33,6 +34,7 @@ include(${PROJECT_DEFS})
add_subdirectory(utils) add_subdirectory(utils)
add_subdirectory(csl) add_subdirectory(csl)
add_subdirectory(drivers) add_subdirectory(drivers)
add_subdirectory(device_drivers)
message("${BoldBlue}Project Info ${ColourReset}") message("${BoldBlue}Project Info ${ColourReset}")
message("${Blue} |--> Exec Name \t: ${EXECUTABLE} ${ColourReset}") message("${Blue} |--> Exec Name \t: ${EXECUTABLE} ${ColourReset}")
@ -40,6 +42,8 @@ message("${Blue} |--> Compiler Def\t: ${COMPILER_DEFS} ${ColourReset}")
message("${Blue} |--> Project Def\t: ${PROJECT_DEFS} ${ColourReset}") message("${Blue} |--> Project Def\t: ${PROJECT_DEFS} ${ColourReset}")
message("${Blue} |--> Interfaces Dir\t: ${INTERFACES_DIR} ${ColourReset}") message("${Blue} |--> Interfaces Dir\t: ${INTERFACES_DIR} ${ColourReset}")
message("${Blue} |--> Libs used\t\t: ${EXTRA_LIBS} ${ColourReset}") message("${Blue} |--> Libs used\t\t: ${EXTRA_LIBS} ${ColourReset}")
message("${Blue} |--> Drivers Dir\t: ${DRIVERS_DIR} ${ColourReset}")
message("${Blue} |--> Device Driver Dir\t: ${DEVICE_DRIVERS_DIR} ${ColourReset}")
#################################################################################################### ####################################################################################################
#EXECUTABLE #EXECUTABLE

@ -20,21 +20,366 @@
extern "C" { extern "C" {
#endif #endif
#include <stdint.h>
#include "hardwareDescription.h" #include "hardwareDescription.h"
#include "pin.h"
/** This is the spi hardware channel class*/ // TODO: when everything worksmove this into imp.spi.c
//#include "hardwareDescription.h"
//#define SPI_BASE ((SPI_TypeDef *)spiBase_Addr_List[spi_hw_ch])
void spi_init(spiCH_t spi_hw_ch); /*! Enum of possible States*/
typedef enum{
SPI_SLAVE,
SPI_MASTER
} spi_mode_t;
/* Enum of clock polarities*/
typedef enum{
SPI_NONINVERTED,
SPI_INVERTED
}spi_clkPol_t;
/*! Enum of phases*/
typedef enum{
SPI_CAPTURE_ON_FIRST_CLK_TRANSITION,
SPI_CAPTURE_ON_SECCOND_CLK_TRANSITION
} spi_phase_t;
/*! Enum of frame formats*/
typedef enum{
SPI_MSB_FIRST,
SPI_LSB_FIRST
}spi_framef_t;
/*! Enum of frame lenghts*/
typedef enum{
SPI_FRAME_LENGTH_8BIT,
SPI_FRAME_LENGTH_16BIT
}spi_framel_t;
/*! Enum of communication mode*/
typedef enum{
SPI_DOUPLEX,
SPI_SIMPLEX
}spi_comMode_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;
typedef uint8_t (*readReg_t) (uint8_t);
// generic code
/** TODO: setup init with all attributes
* TODO: setup auto pin set alternate function
* @brief This is the spi hardware channel class
* @param spi_hw_ch SPI hardware channel
*/
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);
/**
* \brief Set up SPI channel
* Set up a SPI channel by passig a hardware SPI channel and a chipselect pin.
* The chipselect pin will be set to high (chipselect is lowactive).
* \param *ch pointer to SPI channel
* \param spi_hw_ch SPI hardware channel
* \param chipslectPin designated pin for chipslect
*/
void spiSetupCH(
spi_ch_t *ch,
spiCH_t spi_hw_ch,
pinNo_t chipselectPin);
/**
* \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 spiReadReg(
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 spiAutoReadBlock(
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 spiWriteReg(
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 spiWriteBlock(
spi_ch_t *spi_ch,
uint8_t start_address,
const uint8_t *data,
uint8_t data_len);
/**
* \brief write 8 bits
* \param bits 8 bits
*/
void spiWrite8bit(
spi_ch_t *spi_ch,
uint8_t bits);
/**
* \brief read and write simultainously 8 bits
* \param bits 8 bits
* \return 8 bits
*/
uint8_t spiReadWrite8bit(
spi_ch_t *spi_ch,
uint8_t bits);
/**
* \brief write 16 bits
* \param bits 16 bits
*/
void spiWrite16bit(
spi_ch_t *spi_ch,
uint16_t bits);
/**
* \brief read and write simultainously 16 bits
* \param bits 16 bits
* \return 16 bits
*/
uint16_t spiReadWrite16bit(
spi_ch_t *spi_ch,
uint16_t bits);
/**
* \brief write 32 bits
* \param bits 32 bits
*/
void spiWrite32bit(
spi_ch_t *spi_ch,
uint32_t bits);
/**
* \brief read and write simultainously 32 bits
* \param bits 32 bits
* \return 32 bits
*/
uint32_t spiReadWrite32bit(
spi_ch_t *spi_ch,
uint8_t bits);
// implementation
/**
* @brief SPI hardware peripheral reset
* @param spi_hw_ch SPI hardware channel
*/
void spiReset(
spiCH_t spi_hw_ch);
/**
* @brief Enable Bus for SPI
* @param spi_hw_ch SPI hardware channel
*/
void spiEnableBus(
spiCH_t spi_hw_ch);
/**
* @brief Enable SPI hardware channel
* @param spi_hw_ch SPI hardware channel
*/
void spiEnable(
spiCH_t spi_hw_ch);
/**
* @brief Dissable SPI hardware channel
* @param spi_hw_ch SPI hardware channel
*/
void spiDissable(
spiCH_t spi_hw_ch);
/**
* @brief Set SPI operation mode (MASTER or SLAVE)
* @param spi_hw_ch SPI hardware channel
* @param mode
*/
void spiSetMode(
spiCH_t spi_hw_ch,
spi_mode_t mode);
/**
* @brief Set SPI clock polarity
* @param spi_hw_ch SPI hardware channel
* @param clkPol Clock polarity
*/
void spiSetPolarity(
spiCH_t spi_hw_ch,
spi_clkPol_t clkPol);
/**
* @breif Get SPI polarity
* @param spi_hw_ch SPI hardware channel
* @return polarity
*/
spi_clkPol_t spiGetPolarity(
spiCH_t spi_hw_ch);
/**
* @brief Set SPI clock phase
* @param spi_hw_ch SPI hardware channel
* @param phase
*/
void spiSetPhase(
spiCH_t spi_hw_ch,
spi_phase_t phase);
/**
* @brief Get SPI clock phase
* @param spi_hw_ch SPI hardware channel
* @return phase
*/
spi_phase_t spiGetPhase(
spiCH_t spi_hw_ch);
/**
* @brief Set frame length
* one can choose between 4/8/16 bits. For devices that not support a given frame length an error
* will be generated.
* @param spi_hw_ch SPI hardware channel
* @param framel Frame length
*/
void spiSetBitFrameLength(
spiCH_t spi_hw_ch,
spi_framel_t framel);
/**
* @brief Set SPI frame format
* @param spi_hw_ch SPI hardware channel
* @param framef Frame format
*/
void spiSetFrameFormat(
spiCH_t spi_hw_ch,
spi_framef_t framef);
/**
* @brief Get SPI frame format
* @param spi_hw_ch SPI hardware channel
* @return Frame format
*/
spi_framef_t spiGetFrameFormat(
spiCH_t spi_hw_ch);
/**
* @brief Set Clock Prescaler
* This is dependent on your target device. Please enter in the correct value.
* The entered Value will be masked with the maximal number of bits (truncated)
* @param spi_hw_ch SPI hardware channel
* @param clkDiv
*/
void spiSetClockPrescaler(
spiCH_t spi_hw_ch,
uint32_t clkDiv);
/**
* @brief Set communication Mode
* @param spi_hw_ch SPI hardware channel
* @param comMode
*/
void spiSetComMode(
spiCH_t spi_hw_ch,
spi_comMode_t comMode);
/**
* @brief Get Clock Prescaler
* @param spi_hw_ch SPI hardware channel
* @return prescaler
*/
uint32_t spiGetClockPrescaler(
spiCH_t spi_hw_ch);
#if 0
/**
* @brief Set software slave management
* @param logic 1 = enabled, 0 = dissabled
*/
void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic);
#endif
/**
* @brief Enable software slave management
* @param spi_hw_ch SPI hardware channel
* @param logic Slave management done by software... 1 = enables / 0 = dissabled
*/
void spiSetSoftwareSlaveManagement(
spiCH_t spi_hw_ch,
uint8_t logic);
/**
* @brief Enable internal slave select
* @param spi_hw_ch SPI hardware channel
* @param logic 1 = enable / 0 = dissable
*/
void spiSetInternalSlaveSelect(
spiCH_t spi_hw_ch,
uint8_t logic);
/*! /*!
* @brief Transmits and receives on byte of data * @brief Transmits and receives one byte of data in polling mode
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @param tx_data 'tx_data' The byte to be transmitted" * @param tx_data 'tx_data' The byte to be transmitted"
* @return The received data * @return The received data
*/ */
uint8_t spi_trx(spiCH_t spi_hw_ch, uint8_t tx_data); uint8_t spiTrx8BitPolling(
spiCH_t spi_hw_ch,
uint8_t tx_data);
#ifdef __cplusplus #ifdef __cplusplus

@ -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

@ -230,18 +230,46 @@ static const uint32_t timerRes_Prescaler[MAX_TIMER_CHANNEL_COUNT] = {
0xFFFF, /*!< Timer 17 Prescaler Max Value */ 0xFFFF, /*!< Timer 17 Prescaler Max Value */
}; };
/*!
* RCC Bus number index list connected to the SPI
* */
static const uint8_t spiBus_No[MAX_SPI_CHANNEL_COUNT] = {
2, /*!< SPI 1 is connected to bus 2 */
1 /*!< SPI 2 is connected to bus 1 */
};
/*!
* RCC SPI clock enable bit position for the given register
*
*/
static const uint8_t spiBus_En_bitPos[MAX_SPI_CHANNEL_COUNT] = {
RCC_APB2ENR_SPI1EN_Pos,
RCC_APB1ENR_SPI2EN_Pos
};
/*!
* RCC SPI Reset Bit Position list
* */
static const uint8_t spiBus_Rst_bitPos[MAX_SPI_CHANNEL_COUNT] = {
RCC_APB2RSTR_SPI1RST_Pos,
RCC_APB1RSTR_SPI2RST_Pos
};
/**
* Enumof available spi hardware channels
*/
typedef enum{ typedef enum{
SPI_CH_1, SPI_CH_1,
SPI_CH_2 SPI_CH_2
} spiCH_t; } spiCH_t;
/**
* SPI base address list
*/
static const uint32_t spiBase_Addr_List[MAX_SPI_CHANNEL_COUNT] = { static const uint32_t spiBase_Addr_List[MAX_SPI_CHANNEL_COUNT] = {
SPI1_BASE, SPI1_BASE,
SPI2_BASE SPI2_BASE
}; };
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -29,9 +29,9 @@ target_compile_definitions(stmTimer PRIVATE ${C_DEFS})
target_include_directories(stmTimer PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES}) target_include_directories(stmTimer PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES})
add_library(sub::timer ALIAS stmTimer) add_library(sub::timer ALIAS stmTimer)
add_library(stmSPI spi.c) add_library(stmSPI imp_spi.c)
target_compile_options(stmSPI PRIVATE ${C_FLAGS}) target_compile_options(stmSPI PRIVATE ${C_FLAGS})
target_compile_definitions(stmSPI PRIVATE ${C_DEFS}) target_compile_definitions(stmSPI PRIVATE ${C_DEFS})
target_include_directories(stmSPI PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES}) target_include_directories(stmSPI PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES})
add_library(sub::spi ALIAS stmSPI) add_library(sub::imp_spi ALIAS stmSPI)

@ -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
}

@ -71,10 +71,13 @@ set (MAIN_FLAGS ${C_FLAGS})
set (MAIN_DEFS ${C_DEFS}) set (MAIN_DEFS ${C_DEFS})
list(APPEND EXTRA_LIBS sub::startup) list(APPEND EXTRA_LIBS sub::startup)
#list(APPEND EXTRA_LIBS sub::translator)
list(APPEND EXTRA_LIBS sub::delay) list(APPEND EXTRA_LIBS sub::delay)
list(APPEND EXTRA_LIBS sub::pin)
list(APPEND EXTRA_LIBS sub::usart)
list(APPEND EXTRA_LIBS sub::timer) list(APPEND EXTRA_LIBS sub::timer)
list(APPEND EXTRA_LIBS sub::usart)
list(APPEND EXTRA_LIBS sub::init) list(APPEND EXTRA_LIBS sub::init)
list(APPEND EXTRA_LIBS sub::max7219)
list(APPEND EXTRA_LIBS sub::spi) list(APPEND EXTRA_LIBS sub::spi)
list(APPEND EXTRA_LIBS sub::imp_spi)
list(APPEND EXTRA_LIBS sub::pin)
list(APPEND EXTRA_LIBS sub::ad9833)

@ -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);
}

@ -4,6 +4,7 @@ CSL_TO_USE=$1
CSL_LIST=$(ls -d -- ./csl) CSL_LIST=$(ls -d -- ./csl)
FILE=build/ FILE=build/
clear
if [ -z "$CSL_TO_USE" ];then if [ -z "$CSL_TO_USE" ];then
echo "Please enter a CSL" echo "Please enter a CSL"

108
main.c

@ -5,51 +5,20 @@
#include "ascii.h" #include "ascii.h"
#include "timer.h" #include "timer.h"
#include "spi.h" #include "spi.h"
#include "max7219.h"
void timer_test(timerNo_t timer, pinNo_t pin) #include "ad9833.h"
{
timerInitCounter(timer, 4000, 999, downCounting);
timerSart(timer);
for(int i = 0; i < 10 ; i++)
{
while(!timerGetUpdateInterrupt(timer));
timerClearUpdateInterrupt(timer);
pinToggle(pin);
}
pinWrite(pin,0);
}
void timer_capture_compare_test(timerNo_t timer)
{
uint16_t i = 0;
timerInitCounter(timer, 100, 99, downCounting);
// We use pin PA3 (Arduino header A2)
//timerInitOutputCompare(timer, toggle, 4, pinA3, 2,0, 300);
timerInitOutputCompare(timer, pwm_normal, 2, pinB3, 2,0, 900);
timerSart(timer);
while(1){
delayMs(200);
timerSetCounterCompareValue(timer, 2, i);
i += 10;
if(i>99) i = 0;
}
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
uint8_t i = 0; uint8_t i = 0;
uint8_t j = 0;
// making array with all available timers
timerNo_t timers[MAX_TIMER_CHANNEL_COUNT] = {timer_1, timer_2, timer_3, timer_14, timer_16, timer_17}; spi_ch_t spi_test_channel;
// making array with all available timers
delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library
pinConfig(pinB3, output, pushPull, def_res, def_speed); pinConfig(pinB3, output, pushPull, output, def_speed);
pinConfig(pinA0, input, def_stage, pullDown, def_speed); pinConfig(pinA0, input, def_stage, pullDown, def_speed);
setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main. setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main.
@ -68,47 +37,58 @@ int main(int argc, char *argv[])
print_Usart(usart2, "HEllooo to our KED project\n\r"); print_Usart(usart2, "HEllooo to our KED project\n\r");
//blinks 10 times to indicate the sicsessfull init if the device for(i = 0 ; i < 5 ; i++) {
for(i = 0 ; i < 10 ; i++) {
delayMs(100); delayMs(100);
pinToggle(pinB3); pinToggle(pinB3);
delayMs(100); delayMs(100);
} }
pinWrite(pinB3,0);
pinInit(pinA5);
pinInit(pinA6);
pinInit(pinA7);
pinSetAlternate(pinA5, 0); // SPI1_SCK pinWrite(pinB3,0);
pinSetAlternate(pinA6, 0); // SPI1_MISO
pinSetAlternate(pinA7, 0); // SPI1_MOSI
spi_init(SPI_CH_1); pinInit(pinA3);
//pinConfig(pinA6, alternate, floating, pullDown, veryFast);
pinConfig(pinA3, output, pushPull, output, veryFast);
// spi hardware channel setup
spiInitMaster(SPI_CH_1,
SPI_NONINVERTED,
SPI_CAPTURE_ON_FIRST_CLK_TRANSITION,
SPI_MSB_FIRST,
SPI_DOUPLEX,
7,
pinA5,
0,
pinA7,
0,
pinA6,
0);
for(i = 0 ; i < 20 ; i++) { spiSetupCH(&spi_test_channel, SPI_CH_1, pinA3);
spiEnable(SPI_CH_1);
/*
* SPI hoockup for this example
*
* Signal pin nucleo
* --------------------------
* MOSI pinA7 A6
* MISO pinA6 A5
* CLK pinA5 A4
* CS pinA4 A3
*/
for(i = 0 ; i < 10 ; i++) {
delayMs(50); delayMs(50);
pinToggle(pinB3); pinToggle(pinB3);
delayMs(50); delayMs(50);
} }
for(i = 10; i > 0; i--) {
spi_trx(SPI_CH_1, 0xAE);
}
for(i = 0 ; i < 10 ; i++) {
delayMs(100);
pinToggle(pinB3);
delayMs(100);
}
//timer_capture_compare_test(timer_2);
//print_Usart(usart2, "All is working fine \r\n");
while(1) while(1)
{ {
} }
return 1; return 1;

@ -3,21 +3,9 @@
dir=$(pwd) dir=$(pwd)
echo $dir echo $dir
tmux new -s 'git' -d 'fish' cd $dir/ked/
tmux new -s 'compile' -d 'fish' tmux -2 new -s 'compile' -d 'fish'
tmux new -s 'main' -d 'fish'
cd $dir/ked/csl/stm32f042/Src/
tmux new -s 'src' -d 'fish'
cd $dir/ked/csl/stm32f042/Device/
tmux new -s 'device' -d 'fish'
cd $dir/ked/csl/interfaces/ tmux -2 new -s 'workbench' -d 'fish'
tmux new -s 'interface' -d 'fish'
cd $dir/ked/
tmux new -s 'KED submodule' -d 'fish'
tmux a

Loading…
Cancel
Save