Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
light_ws2812_arch.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Xavier Paris <xavier.paris@enac.fr>
3 *
4 * This file is part of paparazzi
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
29/****************************************************************************************
30https://github.com/joewa/WS2812-LED-Driver_ChibiOS/
31****************************************************************************************/
32
33#include <hal.h>
36#include "mcu_periph/gpio.h"
38#include "mcu_periph/ram_arch.h"
39
40#include BOARD_CONFIG
41
42// STM32H7 names the system clock STM32_SYS_CK
43#if !defined(STM32_SYSCLK) && defined(STM32_SYS_CK)
44#define STM32_SYSCLK STM32_SYS_CK
45#endif
46
47#define WS2812_SERVO_HZ 800000
48#define WS2812_PWM_FREQUENCY (STM32_SYSCLK/2)
49
50#define WS2812_DUTYCYCLE_0 (WS2812_PWM_FREQUENCY/(1000000000/350))
51#define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY/(1000000000/800))
52
53#define WS2812_RESET_BIT_N (50)
54#define WS2812_COLOR_BIT_N (WS2812_NB_LEDS * 24)
55#define WS2812_BIT_N (WS2812_COLOR_BIT_N + WS2812_RESET_BIT_N)
56
57// Use driver 1 by default
58#ifndef WS2812_CFG_DEF
59#define WS2812_GPIO WS2812D1_GPIO
60#define WS2812_PIN WS2812D1_PIN
61#define WS2812_AF WS2812D1_AF
62#define WS2812_CFG_DEF WS2812D1_CFG_DEF
63#endif
64
65#define WS2812_DMA_IRQ_PRIORITY 6
66
70typedef struct {
72#if STM32_DMA_SUPPORTS_DMAMUX
74#else
76#endif
81
82// Config from board conf
84
94
95// Driver
97
98// DMA buffer, must be in a DMA reachable (and on H7 non-cached) section
100
102{
103
105
106 uint32_t i;
107 for (i = 0; i < WS2812_COLOR_BIT_N; i++) {
109 }
110 for (i = 0; i < WS2812_RESET_BIT_N; i++) {
112 }
113
115
118#if STM32_DMA_SUPPORTS_DMAMUX
119 .dmamux = WS2812CFG.dmamux,
120#else
121 .channel = WS2812CFG.dma_channel,
122#endif
123 .dma_priority = WS2812CFG.dma_priority,
124 .irq_priority = WS2812_DMA_IRQ_PRIORITY,
125 .direction = DMA_DIR_M2P,
126 .psize = 4,
127 .msize = 4,
128 .inc_peripheral_addr = false,
129 .inc_memory_addr = true,
131 .error_cb = NULL,
132 .end_cb = NULL,
133 .pburst = 0,
134 .mburst = 0,
135 .fifo = 0
136 };
137
139 .frequency = WS2812_PWM_FREQUENCY,
141 .callback = NULL,
142 .channels = {
143 {
144 .mode = PWM_OUTPUT_DISABLED,
145 .callback = NULL
146 },
147 {
148 .mode = PWM_OUTPUT_DISABLED,
149 .callback = NULL
150 },
151 {
152 .mode = PWM_OUTPUT_DISABLED,
153 .callback = NULL
154 },
155 {
156 .mode = PWM_OUTPUT_DISABLED,
157 .callback = NULL
158 },
159 },
160 .cr2 = 0,
161 .dier = STM32_TIM_DIER_UDE
162 };
163
167
171}
172
173#define WS2812_BIT(led, byte, bit) (24*(led) + 8*(byte) + (7 - (bit)))
174#define WS2812_RED_BIT(led, bit) WS2812_BIT((led), 1, (bit))
175#define WS2812_GREEN_BIT(led, bit) WS2812_BIT((led), 0, (bit))
176#define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 2, (bit))
177
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
Setup a gpio for input or output with alternate function.
Definition gpio_arch.c:65
Some architecture independent helper functions for GPIOs.
void dmaObjectInit(DMADriver *dmap)
bool dmaStartTransfert(DMADriver *dmap, volatile void *periphp, void *mem0p, const size_t size)
Starts a DMA transaction.
bool dmaStart(DMADriver *dmap, const DMAConfig *cfg)
Configures and activates the DMA peripheral.
STM32 DMA subsystem driver header.
@ DMA_CONTINUOUS_HALF_BUFFER
Continuous mode to/from the same buffer.
@ DMA_DIR_M2P
MEMORY to PERIPHERAL
uint32_t stream
stream associated with transaction
DMA stream configuration structure.
Structure representing a DMA driver.
#define WS2812_GREEN_BIT(led, bit)
#define WS2812_DMA_IRQ_PRIORITY
static WS2812Driver WS2812D
#define WS2812_BLUE_BIT(led, bit)
#define WS2812_AF
#define WS2812_RESET_BIT_N
#define WS2812_SERVO_HZ
static WS2812Config WS2812CFG
#define WS2812_PWM_FREQUENCY
#define WS2812_DUTYCYCLE_0
const WS2812Config * config
#define WS2812_COLOR_BIT_N
void light_ws2812_arch_set(uint32_t led_number, uint8_t r, uint8_t g, uint8_t b)
set color RGB color of one led
void light_ws2812_arch_init(void)
PWMDriver * pwmp
#define WS2812_CFG_DEF
#define WS2812_DUTYCYCLE_1
#define WS2812_GPIO
#define WS2812_PIN
#define WS2812_BIT_N
#define WS2812_RED_BIT(led, bit)
Configuration structure.
Driver structure.
ws2812 driver based on ChibiOS
#define WS2812_NB_LEDS
Number of LEDs.
uint16_t foo
Definition main_demo5.c:58
static float g
Specific RAM section for DMA usage on F7.
#define IN_DMA_SECTION_CLEAR(var)
Definition ram_arch.h:86
Implementation of system time functions for ChibiOS arch.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
float b
Definition wedgebug.c:202