px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_board.h
1#ifndef __PX_BOARD_H__
2#define __PX_BOARD_H__
3/* =============================================================================
4 ____ ___ ____ ___ _ _ ___ __ __ ___ __ __ TM
5 | _ \ |_ _| / ___| / _ \ | \ | | / _ \ | \/ | |_ _| \ \/ /
6 | |_) | | | | | | | | | | \| | | | | | | |\/| | | | \ /
7 | __/ | | | |___ | |_| | | |\ | | |_| | | | | | | | / \
8 |_| |___| \____| \___/ |_| \_| \___/ |_| |_| |___| /_/\_\
9
10 Copyright (c) 2017 Pieter Conradie <https://piconomix.com>
11
12 License: MIT
13 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
14
15 Title: board.h : STM32L072RB PX-HER0 Board
16 Author(s): Pieter Conradie
17 Creation Date: 2017-11-13
18
19============================================================================= */
20/**
21 * @ingroup BOARDS_STM32
22 * @defgroup BOARDS_STM32_PX_HERO px_board.h : STM32L072RB PX-HER0 Board
23 *
24 * File(s):
25 * - boards/arm/stm32/px_hero/inc/px_board.h
26 * - boards/arm/stm32/px_hero/inc/px_board_gpio.h
27 * - boards/arm/stm32/px_hero/src/px_board.c
28 *
29 * @{
30 */
31
32/* _____STANDARD INCLUDES____________________________________________________ */
33
34/* _____PROJECT INCLUDES_____________________________________________________ */
35#include "px_defs.h"
36#include "px_board_gpio.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41/* _____DEFINITIONS__________________________________________________________ */
42/// Board name
43#define PX_BOARD_PX_HERO
44
45/// System clock frequency in Hz
46#define PX_BOARD_SYS_CLK_HZ 32000000ul
47
48/// Peripheral clock frequency in Hz
49#define PX_BOARD_PER_CLK_HZ PX_BOARD_SYS_CLK_HZ
50
51/* _____TYPE DEFINITIONS_____________________________________________________ */
52/// Identify which GPIO pins are used for CS in px_board_spi_cs_lo() and px_board_spi_cs_hi()
53typedef enum
54{
55 PX_BOARD_SPI_CS_NONE, ///< Do not perform a chip select
56 PX_BOARD_SPI1_CS, ///< Peripheral CS
57 PX_BOARD_SPI1_CS_SD, ///< SD Card
58 PX_BOARD_SPI2_CS_LCD, ///< JHD JHD12864-G176BSW 128x64 monochrome LCD
59 PX_BOARD_SPI2_CS_SF, ///< Adesto AT25S Serial FLASH
61
62/// @name Mapping of board's ADC pins to ADC channels
63/// @{
64#define PX_BOARD_ADC0 PX_ADC_CH8
65#define PX_BOARD_ADC1 PX_ADC_CH15
66#define PX_BOARD_ADC2 PX_ADC_CH14
67#define PX_BOARD_ADC3 PX_ADC_CH7
68#define PX_BOARD_ADC_VBAT PX_ADC_CH9
69/// @}
70
71/* _____GLOBAL VARIABLES_____________________________________________________ */
72
73/* _____GLOBAL FUNCTION DECLARATIONS_________________________________________ */
74/// Initialise the board hardware
75void px_board_init(void);
76
77/**
78 * Set specified SPI Chip Select low
79 *
80 * @param cs_id ID which GPIO pin must be used for Chip Select
81 */
82void px_board_spi_cs_lo(uint8_t cs_id);
83
84/**
85 * Set specified SPI Chip Select high
86 *
87 * @param cs_id ID which GPIO pin must be used for Chip Select
88 */
89void px_board_spi_cs_hi(uint8_t cs_id);
90
91/**
92 * Initialise Timer 6 with 1 us clock ticks for delay use
93 *
94 */
95void px_board_delay_init(void);
96
97/**
98 * Disable Timer 6
99 *
100 */
101void px_board_delay_deinit(void);
102
103/**
104 * Blocking delay for specified number of microseconds.
105 *
106 * @param delay_us Number of microseconds to block
107 */
108void px_board_delay_us(uint16_t delay_us);
109
110/**
111 * Blocking delay for specified number of milliseconds.
112 *
113 * @param delay_ms Number of milliseconds to block
114 */
115void px_board_delay_ms(uint16_t delay_ms);
116
117/**
118 * Enable PWM output to piezo buzzer at specified frequency.
119 *
120 * @param freq_hz PWM frequency in Hz
121 */
122void px_board_buzzer_on(uint16_t freq_hz);
123
124/**
125 * Disable PWM output to piezo buzzer.
126 */
127void px_board_buzzer_off(void);
128
129/**
130 * Enable DBG module during SLEEP and STOP mode.
131 *
132 */
133void px_board_dbg_enable(void);
134
135/**
136 * Disable DBG module.
137 */
138void px_board_dbg_disable(void);
139
140/**
141 * Enter low power STOP mode and wait for interrupt to wake up core
142 *
143 * NB! Debug module must be disabled during STOP mode, otherwise SysTick
144 * interrupt will wake up core.
145 */
146void px_board_stop_mode(void);
147
148
149/* _____MACROS_______________________________________________________________ */
150/// User button
151#define PX_USR_PB_IS_PRESSED() px_gpio_in_is_lo(&px_gpio_lcd_btn_6_no)
152
153/// User LED
154#define PX_USR_LED_ON() px_gpio_out_set_hi(&px_gpio_usr_led)
155#define PX_USR_LED_OFF() px_gpio_out_set_lo(&px_gpio_usr_led)
156#define PX_USR_LED_TOGGLE() px_gpio_out_toggle(&px_gpio_usr_led)
157
158/// LCD
159#define PX_LCD_RS_LO() px_gpio_out_set_lo(&px_gpio_lcd_rs)
160#define PX_LCD_RS_HI() px_gpio_out_set_hi(&px_gpio_lcd_rs)
161#define PX_LCD_BACKLIGHT_ON() px_gpio_out_set_lo(&px_gpio_lcd_backlight)
162#define PX_LCD_BACKLIGHT_OFF() px_gpio_out_set_hi(&px_gpio_lcd_backlight)
163
164// SD Card
165#define PX_SD_CARD_DETECTED() px_gpio_in_is_lo(&px_gpio_7_sd_cd)
166
167// Battery voltage measurement
168#define PX_VBAT_MEAS_ENABLE() px_gpio_out_set_hi(&px_gpio_vbat_meas_en)
169#define PX_VBAT_MEAS_DISABLE() px_gpio_out_set_lo(&px_gpio_vbat_meas_en)
170
171// Power hold
172#define PX_POWER_OFF() px_gpio_out_set_lo(&px_gpio_3v3_hold)
173
174#ifdef __cplusplus
175}
176#endif
177
178/// @}
179#endif
@ PX_BOARD_SPI_CS_NONE
Do not perform a chip select.
Definition: px_board.h:55
@ PX_BOARD_SPI1_CS
Peripheral CS.
Definition: px_board.h:56
@ PX_BOARD_SPI1_CS_SD
SD Card.
Definition: px_board.h:57
@ PX_BOARD_SPI2_CS_SF
Adesto AT25S Serial FLASH.
Definition: px_board.h:59
@ PX_BOARD_SPI2_CS_LCD
JHD JHD12864-G176BSW 128x64 monochrome LCD.
Definition: px_board.h:58
void px_board_delay_init(void)
Initialise Timer 6 with 1 us clock ticks for delay use.
Definition: px_board.c:204
void px_board_delay_us(uint16_t delay_us)
Blocking delay for specified number of microseconds.
Definition: px_board.c:222
void px_board_init(void)
Initialise the board hardware.
Definition: px_board.c:168
void px_board_stop_mode(void)
Enter low power STOP mode and wait for interrupt to wake up core.
Definition: px_board.c:306
px_board_spi_cs_t
Identify which GPIO pins are used for CS in px_board_spi_cs_lo() and px_board_spi_cs_hi()
Definition: px_board.h:54
void px_board_dbg_enable(void)
Enable DBG module during SLEEP and STOP mode.
Definition: px_board.c:278
void px_board_delay_ms(uint16_t delay_ms)
Blocking delay for specified number of milliseconds.
Definition: px_board.c:234
void px_board_buzzer_on(uint16_t freq_hz)
Enable PWM output to piezo buzzer at specified frequency.
Definition: px_board.c:243
void px_board_spi_cs_hi(uint8_t cs_id)
Set specified SPI Chip Select high.
Definition: px_board.c:192
void px_board_dbg_disable(void)
Disable DBG module.
Definition: px_board.c:292
void px_board_delay_deinit(void)
Disable Timer 6.
Definition: px_board.c:216
void px_board_spi_cs_lo(uint8_t cs_id)
Set specified SPI Chip Select low.
Definition: px_board.c:180
void px_board_buzzer_off(void)
Disable PWM output to piezo buzzer.
Definition: px_board.c:269