px-lib  0.9.3
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers
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/piconomix-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_PICONOMIX_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 /* _____STANDARD INCLUDES____________________________________________________ */
32 
33 /* _____PROJECT INCLUDES_____________________________________________________ */
34 #include "px_defines.h"
35 #include "px_board_gpio.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 /* _____DEFINITIONS__________________________________________________________ */
41 /// Board name
42 #define PX_BOARD_PICONOMIX_HERO_BOARD
43 
44 /// System clock frequency in Hz
45 #define PX_BOARD_SYS_CLK_HZ 32000000ul
46 
47 /// Peripheral clock frequency in Hz
48 #define PX_BOARD_PER_CLK_HZ PX_BOARD_SYS_CLK_HZ
49 
50 /* _____TYPE DEFINITIONS_____________________________________________________ */
51 /// Identify which GPIO pins are used for CS in px_board_spi_cs_lo() and px_board_spi_cs_hi()
52 typedef enum
53 {
54  PX_BOARD_SPI_CS_NONE, ///< Do not perform a chip select
55  PX_BOARD_SPI1_CS, ///< Peripheral CS
56  PX_BOARD_SPI1_CS_SD, ///< SD Card
57  PX_BOARD_SPI2_CS_LCD, ///< JHD JHD12864-G176BSW 128x64 monochrome LCD
58  PX_BOARD_SPI2_CS_SF, ///< Adesto AT25S Serial FLASH
60 
61 /// @name Mapping of board's ADC pins to ADC channels
62 //@{
63 #define PX_BOARD_ADC0 PX_ADC_CH8
64 #define PX_BOARD_ADC1 PX_ADC_CH15
65 #define PX_BOARD_ADC2 PX_ADC_CH14
66 #define PX_BOARD_ADC3 PX_ADC_CH7
67 #define PX_BOARD_ADC_VBAT PX_ADC_CH9
68 //@}
69 
70 /* _____GLOBAL VARIABLES_____________________________________________________ */
71 
72 /* _____GLOBAL FUNCTION DECLARATIONS_________________________________________ */
73 /// Initialise the board hardware
74 void px_board_init(void);
75 
76 /**
77  * Set specified SPI Chip Select low
78  *
79  * @param cs_id ID which GPIO pin must be used for Chip Select
80  */
81 void px_board_spi_cs_lo(uint8_t cs_id);
82 
83 /**
84  * Set specified SPI Chip Select high
85  *
86  * @param cs_id ID which GPIO pin must be used for Chip Select
87  */
88 void px_board_spi_cs_hi(uint8_t cs_id);
89 
90 /**
91  * Initialise Timer 6 with 1 us clock ticks for delay use
92  *
93  */
94 void px_board_delay_init(void);
95 
96 /**
97  * Disable Timer 6
98  *
99  */
100 void px_board_delay_deinit(void);
101 
102 /**
103  * Blocking delay for specified number of microseconds.
104  *
105  * @param delay_us Number of microseconds to block
106  */
107 void px_board_delay_us(uint16_t delay_us);
108 
109 /**
110  * Blocking delay for specified number of milliseconds.
111  *
112  * @param delay_ms Number of milliseconds to block
113  */
114 void px_board_delay_ms(uint16_t delay_ms);
115 
116 /**
117  * Enable PWM output to piezo buzzer at specified frequency.
118  *
119  * @param freq_hz PWM frequency in Hz
120  */
121 void px_board_buzzer_on(uint16_t freq_hz);
122 
123 /**
124  * Disable PWM output to piezo buzzer.
125  */
126 void px_board_buzzer_off(void);
127 
128 /**
129  * Enable DBG module during SLEEP and STOP mode.
130  *
131  */
132 void px_board_dbg_enable(void);
133 
134 /**
135  * Disable DBG module.
136  */
137 void px_board_dbg_disable(void);
138 
139 /**
140  * Enter low power STOP mode and wait for interrupt to wake up core
141  *
142  * NB! Debug module must be disabled during STOP mode, otherwise SysTick
143  * interrupt will wake up core.
144  */
145 void px_board_stop_mode(void);
146 
147 
148 /* _____MACROS_______________________________________________________________ */
149 /// User button
150 #define PX_USR_PB_IS_PRESSED() px_gpio_pin_is_lo(&px_gpio_lcd_btn_6_no)
151 
152 /// User LED
153 #define PX_USR_LED_ON() px_gpio_pin_set_hi(&px_gpio_usr_led)
154 #define PX_USR_LED_OFF() px_gpio_pin_set_lo(&px_gpio_usr_led)
155 #define PX_USR_LED_TOGGLE() px_gpio_pin_toggle(&px_gpio_usr_led)
156 
157 /// LCD
158 #define PX_LCD_RS_LO() px_gpio_pin_set_lo(&px_gpio_lcd_rs)
159 #define PX_LCD_RS_HI() px_gpio_pin_set_hi(&px_gpio_lcd_rs)
160 #define PX_LCD_BACKLIGHT_ON() px_gpio_pin_set_lo(&px_gpio_lcd_backlight)
161 #define PX_LCD_BACKLIGHT_OFF() px_gpio_pin_set_hi(&px_gpio_lcd_backlight)
162 
163 // SD Card
164 #define PX_SD_CARD_DETECTED() px_gpio_pin_is_lo(&px_gpio_7_sd_cd)
165 
166 // Battery voltage measurement
167 #define PX_VBAT_MEAS_ENABLE() px_gpio_pin_set_hi(&px_gpio_vbat_meas_en)
168 #define PX_VBAT_MEAS_DISABLE() px_gpio_pin_set_lo(&px_gpio_vbat_meas_en)
169 
170 // Power hold
171 #define PX_POWER_OFF() px_gpio_pin_set_lo(&px_gpio_3v3_hold)
172 
173 /// @}
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif // #ifndef __PX_BOARD_H__
Peripheral CS.
Definition: px_board.h:55
void px_board_stop_mode(void)
Enter low power STOP mode and wait for interrupt to wake up core.
Definition: px_board.c:336
void px_board_dbg_enable(void)
Enable DBG module during SLEEP and STOP mode.
Definition: px_board.c:308
void px_board_spi_cs_lo(uint8_t cs_id)
Set specified SPI Chip Select low.
Definition: px_board.c:201
void px_board_spi_cs_hi(uint8_t cs_id)
Set specified SPI Chip Select high.
Definition: px_board.c:213
void px_board_delay_ms(uint16_t delay_ms)
Blocking delay for specified number of milliseconds.
Definition: px_board.c:258
void px_board_delay_deinit(void)
Disable Timer 6.
Definition: px_board.c:237
JHD JHD12864-G176BSW 128x64 monochrome LCD.
Definition: px_board.h:57
void px_board_buzzer_off(void)
Disable PWM output to piezo buzzer.
Definition: px_board.c:298
Adesto AT25S Serial FLASH.
Definition: px_board.h:58
void px_board_delay_us(uint16_t delay_us)
Blocking delay for specified number of microseconds.
Definition: px_board.c:243
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:52
void px_board_init(void)
Initialise the board hardware.
Definition: px_board.c:186
Do not perform a chip select.
Definition: px_board.h:54
void px_board_delay_init(void)
Initialise Timer 6 with 1 us clock ticks for delay use.
Definition: px_board.c:225
void px_board_buzzer_on(uint16_t freq_hz)
Enable PWM output to piezo buzzer at specified frequency.
Definition: px_board.c:267
void px_board_dbg_disable(void)
Disable DBG module.
Definition: px_board.c:322