7#include "DMX512_driver.h"
17static osThreadId_t DMX512_driver_ThreadId = NULL;
31static void _DMX512_driver_send_frame(
void){
33 this.uart.Init.StopBits = UART_STOPBITS_2;
34 HAL_UART_Init(&this.uart);
47static void _DMX512_driver_send_breakmab(
void){
49 this.uart.Init.StopBits = UART_STOPBITS_1;
50 HAL_UART_Init(&this.uart);
60static void _DMX512_driver_thread(
void *arg){
62 _DMX512_driver_send_breakmab();
63 _DMX512_driver_send_frame();
74uint8_t _DMX512_driver_address_check(uint16_t address){
82void _DMX512_driver_GPIO_init(
void){
84 __USART1_CLK_ENABLE();
87 GPIO_InitTypeDef GPIO_InitStructure;
89 GPIO_InitStructure.Pin = GPIO_PIN_6;
90 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
91 GPIO_InitStructure.Alternate = GPIO_AF7_USART1;
92 GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
93 GPIO_InitStructure.Pull = GPIO_NOPULL;
94 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
96 GPIO_InitStructure.Pin = GPIO_PIN_7;
97 GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
98 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
107void _DMX512_driver_UART_init(
void){
109 this.uart.Instance = USART1;
110 this.uart.Init.WordLength = UART_WORDLENGTH_8B;
111 this.uart.Init.StopBits = UART_STOPBITS_2;
112 this.uart.Init.Parity = UART_PARITY_NONE;
113 this.uart.Init.Mode = UART_MODE_TX_RX;
114 this.uart.Init.HwFlowCtl = UART_HWCONTROL_NONE;
115 this.uart.Init.OverSampling = UART_OVERSAMPLING_16;
117 HAL_UART_Init(&this.uart);
134 if(this.status == DMX512_DRIVER_UNINITIALISED){
135 _DMX512_driver_GPIO_init();
136 _DMX512_driver_UART_init();
137 this.status = DMX512_DRIVER_INITIALISED;
159 const osThreadAttr_t DMX512_driver_thread_attr = {
160 .priority = osPriorityNormal,
161 .stack_size = configMINIMAL_STACK_SIZE*4
164 DMX512_driver_ThreadId = osThreadNew(_DMX512_driver_thread, NULL, &DMX512_driver_thread_attr);
165 return DMX512_driver_ThreadId != NULL ? DMX512_DRIVER_OK : DMX512_DRIVER_THREAD_ERR;
176 return osThreadTerminate(DMX512_driver_ThreadId) == osOK ? DMX512_DRIVER_OK : DMX512_DRIVER_THREAD_ERR;
191 if(!_DMX512_driver_address_check(address)){
192 err = DMX512_DRIVER_ADDRESS_OUT_OF_BOUNDS;
194 this.value_buffer[address] = value;
#define DMX512_CHANNEL_ADDRESS_MAX
DMX512 max channel address.
DMX512_driver_err_e DMX512_driver_set_single(uint16_t address, uint8_t value)
Sets a buffer's address to a given value.
#define DEFAULT_DMX512_DRIVER
DMX512 driver object default values.
#define DMX512_BREAKMAB_BYTESIZE
DMX512_driver_err_e
QLSF DMX512 driver error constants.
DMX512_driver_status_e DMX512_driver_get_status(void)
Returns the status of the DMX512 driver.
#define DMX512_FRAME_BYTESIZE
#define DMX512_BREAKMAB_BYTEDATA
#define DMX512_FRAME_BAUDRATE
#define DMX512_BREAKMAB_BAUDRATE
DMX512_driver_status_e
Status of the DMX512 driver instance.
DMX512_driver_err_e DMX512_driver_start(void)
Starts the DMX512 driver thread.
void DMX512_driver_init(void)
Initialises DMX512 driver periphals.
DMX512_driver_err_e DMX512_driver_stop(void)
Terminates the DMX512 driver thread.
Defines a DMX512 driver instance.