Skip to content

Commit c1a5245

Browse files
committed
Merge branch 'main' into feature/ChongOscar/fmc-support
2 parents 84a0fec + 829eb9f commit c1a5245

23 files changed

Lines changed: 446 additions & 159 deletions

File tree

include/core/io/ADC.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#ifndef _EVT_ADC_
22
#define _EVT_ADC_
33

4+
#include <core/io/pin.hpp>
45
#include <stdint.h>
56

67
namespace core::io {
78

89
// Forward declarations:
910
// The different pins are hardware specific. Forward declarations to allow
1011
// at compilation time the decision of which pins should be used.
11-
enum class Pin;
1212
enum class ADCPeriph;
1313

1414
class ADC {
15-
1615
public:
1716
/**
1817
* Setup the given pin for ADC (analog to digital) usage

include/core/io/CAN.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef _EVT_CAN_
22
#define _EVT_CAN_
33

4-
#include <stdint.h>
5-
4+
#include <core/io/pin.hpp>
65
#include <core/io/types/CANMessage.hpp>
6+
#include <cstdint>
77

88
#ifndef EVT_CAN_TIMEOUT
99
#define EVT_CAN_TIMEOUT 255
@@ -19,11 +19,6 @@
1919
#endif
2020

2121
namespace core::io {
22-
// Forward declarations:
23-
// The different pins are hardware specific. Forward declaration to allow
24-
// at compilation time the decision of which pins should be used.
25-
enum class Pin;
26-
2722
/**
2823
* Generic interface for CAN bus communication. Devices can send and recieve
2924
* messages over the CAN bus using this interface.

include/core/io/GPIO.hpp

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#ifndef _EVT_GPIO_
22
#define _EVT_GPIO_
33

4-
#include <stdint.h>
4+
#include <core/io/pin.hpp>
5+
#include <cstdint>
56

67
namespace core::io {
7-
// Forward declarations:
8-
// The different pins are hardware specific. Forward declaration to allow
9-
// at compilation time the decision of which pins should be used.
10-
enum class Pin;
11-
128
/**
139
* Interface for interacting with GPIO pins on a device. GPIO pins can have
1410
* their state read and written to.
@@ -23,6 +19,53 @@ enum class Pin;
2319
*/
2420
class GPIO {
2521
public:
22+
/**
23+
* A union of a 16-bit number and a breakdown of it in a struct of individual bits.
24+
* the value is meant to quickly set or read a value with ease.
25+
* the struct is meant for individually flipping bits in the field with a friendly format
26+
* Meant for mass GPIO instantiation
27+
*
28+
* Usage Example 1:
29+
* PinPack a = {.value = 0x0010};
30+
* PinPack b = {.pin_4 = 1};
31+
* then
32+
* a == b
33+
*
34+
* Usage Example 2:
35+
* PinPack a = {.pin_4 = 1, .pin_15 = 1};
36+
* then reading from a.value gives
37+
* a.value == 0x8010;
38+
*
39+
* Usage Example 3:
40+
* uint16_t any_number = 0x1111;
41+
* PinPack a;
42+
* a.value = any_number;
43+
* then
44+
* a.pin_12 && a.pin_8 && a.pin_4 && a.pin_0 == 1
45+
*/
46+
union __attribute__((packed)) PinPack {
47+
uint16_t value;
48+
struct {
49+
uint16_t // total size
50+
pin_0 : 1, // Bit 0
51+
pin_1 : 1, // Bit 1
52+
pin_2 : 1, // Bit 2
53+
pin_3 : 1, // Bit 3
54+
pin_4 : 1, // Bit 4
55+
pin_5 : 1, // Bit 5
56+
pin_6 : 1, // Bit 6
57+
pin_7 : 1, // Bit 7
58+
pin_8 : 1, // Bit 8
59+
pin_9 : 1, // Bit 9
60+
pin_10 : 1, // Bit 10
61+
pin_11 : 1, // Bit 11
62+
pin_12 : 1, // Bit 12
63+
pin_13 : 1, // Bit 13
64+
pin_14 : 1, // Bit 14
65+
pin_15 : 1; // Bit 15
66+
};
67+
};
68+
2669
/**
2770
* Binary representation of the states the GPIO can be in
2871
*/
@@ -75,6 +118,29 @@ class GPIO {
75118
*/
76119
GPIO(Pin pin, Direction direction, Pull pull = Pull::PULL_DOWN);
77120

121+
/**
122+
*
123+
* @param pin
124+
* @return uint16_t with the pin number's bit set
125+
*/
126+
static uint16_t setPackBit(Pin pin) {
127+
return 1 << pinNumberFromPin(pin);
128+
}
129+
130+
/**
131+
* Fill a given PinPack based on a given array of pins
132+
*
133+
* @param[out] pp PinPack to be filled given the pin array
134+
* @param[in] pins Array of pins in the same Port
135+
* @param[in] num_pins number of pins in array
136+
*/
137+
static void fillPinPack(PinPack& pp, Pin* pins, uint8_t num_pins) {
138+
pp.value = 0;
139+
for (uint8_t i = 0; i < num_pins; i++) {
140+
pp.value |= setPackBit(pins[i]);
141+
}
142+
}
143+
78144
/**
79145
* Sets whether this pin is configured for input or output.
80146
*

include/core/io/I2C.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _EVT_I2C_
22
#define _EVT_I2C_
33

4+
#include <core/io/pin.hpp>
45
#include <cstdint>
56

67
#define I2C_RETURN_IF_ERR(func) \
@@ -17,7 +18,6 @@ namespace core::io {
1718
// Forward declarations:
1819
// The different pins are hardware specific. Forward declaration to allow
1920
// at compilation time the decision of which pins should be used.
20-
enum class Pin;
2121

2222
/**
2323
* Contains generic implementations for some of the I2C functionality.

include/core/io/PWM.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#ifndef _EVT_PWM_
22
#define _EVT_PWM_
33

4-
#include <stdint.h>
4+
#include <core/io/pin.hpp>
5+
#include <cstdint>
56

67
namespace core::io {
78

8-
// Forward declarations:
9-
// The different pins are hardware specific. Forward declarations to allow
10-
// at compilation time the decision of which pins should be used.
11-
enum class Pin;
12-
139
class PWM {
14-
1510
public:
1611
/**
1712
* Setup the given pin for PWM usage.

include/core/io/SPI.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef _EVT_SPI_
22
#define _EVT_SPI_
33

4-
#include <cstdint>
5-
64
#include <core/io/GPIO.hpp>
5+
#include <core/io/pin.hpp>
6+
#include <cstdint>
77

88
#ifndef EVT_SPI_TIMEOUT
99
#define EVT_SPI_TIMEOUT 100
@@ -23,11 +23,6 @@
2323

2424
namespace core::io {
2525

26-
// Forward declarations:
27-
// The different pins are hardware specific. Forward declaration to allow
28-
// at compilation time the decision of which pins should be used.
29-
enum class Pin;
30-
3126
class SPI {
3227
public:
3328
/**

include/core/io/UART.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _EVT_UART_
22
#define _EVT_UART_
33

4+
#include <core/io/pin.hpp>
45
#include <cstdint>
56
#include <cstdlib>
67

@@ -10,11 +11,6 @@
1011

1112
namespace core::io {
1213

13-
// Forward declarations:
14-
// The different pins are hardware specific. Forward declarations to allow
15-
// at compilation time the decision of which pins should be used.
16-
enum class Pin;
17-
1814
/**
1915
* Interface for UART operations. The UART has the ability for character and
2016
* byte centered operations.

include/core/io/pin.hpp

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef _EVT_PIN_
77
#define _EVT_PIN_
88

9+
#include <cstdint>
10+
911
// TODO: Fix this so that it changes pin out on a per Package Basis instead of a per MCU basis
1012
#ifdef STM32F302x8
1113
#define NUCLEO_SUPPORT
@@ -23,20 +25,22 @@
2325
#define HAS_PORT_D
2426
#define HAS_PORT_E
2527
#define HAS_PORT_F
28+
#define HAS_PORT_G
2629
#define HAS_PORT_H
2730
#define HAS_PORT_I
2831
#endif
2932

3033
namespace core::io {
3134

3235
/**
33-
* Pin mapping information. These values are generated via a combination of the GPIO bank that
34-
* the pin is on and the number of the pin. We referenced MBed's documentation for generating
35-
* these values.
36+
* Pin mapping information. The port is the letter after P, and the pin number is the number after the underscore
37+
*
38+
* PB_10's port is B and pin number is 10
39+
* See the Port enum to see what the value of a Port should be
3640
*/
37-
enum class Pin {
38-
INVALID = -1, // THIS INTENTIONALLY DOES NOT POINT TO A PIN. Used as a default value, so the default value is
39-
// no longer PA_O (a real pin)
41+
enum class Pin : uint8_t {
42+
INVALID = 0xFF, // THIS INTENTIONALLY DOES NOT POINT TO A PIN. Used as a default value, so the default value is
43+
// no longer PA_O (a real pin)
4044
PA_0 = 0x00,
4145
PA_1 = 0x01,
4246
PA_2 = 0x02,
@@ -287,5 +291,46 @@ enum class Pin {
287291
#endif
288292
};
289293

294+
enum class Port : uint8_t {
295+
Invalid = 0xFF,
296+
A = 0x0,
297+
B = 0x1,
298+
C = 0x2,
299+
D = 0x3,
300+
#ifdef HAS_PORT_E
301+
E = 0x4,
302+
#endif
303+
F = 0x5,
304+
#ifdef HAS_PORT_G
305+
G = 0x6,
306+
#endif
307+
#ifdef HAS_PORT_H
308+
H = 0x7,
309+
#endif
310+
#ifdef HAS_PORT_I
311+
I = 0x8,
312+
#endif
313+
};
314+
315+
/**
316+
* Get the port from a Pin
317+
*
318+
* @param pin Pin
319+
* @return Port of the Pin
320+
*/
321+
constexpr Port portFromPin(Pin pin) {
322+
return static_cast<Port>((static_cast<uint32_t>(pin) & 0xF0) >> 4);
323+
}
324+
325+
/**
326+
* Get the pin number from a Pin
327+
*
328+
* @param pin Pin
329+
* @return Pin number of the Pin
330+
*/
331+
constexpr uint8_t pinNumberFromPin(Pin pin) {
332+
return static_cast<uint8_t>(pin) & 0x0F;
333+
}
334+
290335
}; // namespace core::io
291336
#endif

include/core/io/platform/f4xx/GPIOf4xx.hpp

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,57 @@ class GPIOf4xx : public GPIO {
3636
void registerIRQ(TriggerEdge edge, void (*irqHandler)(GPIO* pin, void* priv), void* priv) override;
3737

3838
/**
39+
* DEPRECATED!!!! DO NOT USE
3940
* Condenses gpio settings initialization into a single function.
40-
* @param targetGpio gpio instance to initialize
41-
* @param pins array of pins used by gpio instance
42-
* @param numOfPins size of the pin array (either 1 or 2)
43-
* @param mode gpio configuration mode
44-
* @param pull pull-up or pull-down activation
45-
* @param speed maximum gpio output frequency
41+
* @param[in/out] targetGpio gpio instance to initialize
42+
* @param[in] pins array of pins used by gpio instance
43+
* @param[in] numOfPins size of the pin array (either 1 or 2)
44+
* @param[in] mode gpio configuration mode
45+
* @param[in] pull pull-up or pull-down activation
46+
* @param[in] speed maximum gpio output frequency
4647
* Possible values for Mode, Pull, and Speed can be found in "stm32f4xx_hal_gpio.h"
47-
* @param alternate gpio alternate function selection
48+
* @param[in] alternate gpio alternate function selection
4849
*/
4950
static void gpioStateInit(GPIO_InitTypeDef* targetGpio, Pin* pins, uint8_t numOfPins, uint32_t mode, uint32_t pull,
50-
uint32_t speed, uint8_t alternate = 0x0DU);
51+
uint32_t speed, uint8_t alternate = 0x0E);
52+
53+
/**
54+
* Initialize an arbitrary length array of GPIO pins.
55+
* Does modify the array to be sorted as a result of its implementation
56+
* @param[in] pins Pins to set
57+
* @param[in] numOfPins number of pins in total
58+
* @param[in] mode gpio configuration mode
59+
* @param[in] pull pull-up or pull-down activation
60+
* @param[in] speed maximum gpio output frequency
61+
* Possible values for Mode, Pull, and Speed can be found in "stm32f4xx_hal_gpio.h"
62+
* @param[in] alternate gpio alternate function selection
63+
*/
64+
static void gpioInit(Pin* pins, uint8_t numOfPins, uint32_t mode, uint32_t pull, uint32_t speed,
65+
uint8_t alternate = 0x00);
66+
67+
/**
68+
* Initialize a single GPIO pin
69+
* @param[in] pin Pin to set
70+
* @param[in] mode gpio configuration mode
71+
* @param[in] pull pull-up or pull-down activation
72+
* @param[in] speed maximum gpio output frequency
73+
* Possible values for Mode, Pull, and Speed can be found in "stm32f4xx_hal_gpio.h"
74+
* @param[in] alternate gpio alternate function selection
75+
*/
76+
static void gpioSingleInit(Pin pin, uint32_t mode, uint32_t pull, uint32_t speed, uint8_t alternate = 0x00);
77+
78+
/**
79+
* Mass Initialize GPIO pins with the same value with a grouping by port
80+
* @param[in] pack_pins Byte Array of pins
81+
* @param[in] port Port of the pins to initialize
82+
* @param[in] mode gpio configuration mode
83+
* @param[in] pull pull-up or pull-down activation
84+
* @param[in] speed maximum gpio output frequency
85+
* Possible values for Mode, Pull, and Speed can be found in "stm32f4xx_hal_gpio.h"
86+
* @param[in] alternate gpio alternate function selection
87+
*/
88+
static void gpioPortInit(PinPack pack_pins, Port port, uint32_t mode, uint32_t pull, uint32_t speed,
89+
uint8_t alternate);
5190

5291
private:
5392
// See stm32f4xx_hal_gpio -> GPIO_mode for info on derivations

libs/HALf3/include/HALf3/stm32f3xx_it.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ void SVC_Handler(void);
5656
void DebugMon_Handler(void);
5757
void PendSV_Handler(void);
5858
void SysTick_Handler(void);
59+
/**
60+
* @brief This function does not do anything, but ensures that the compiler/linker works and links together the vectored
61+
* interrupt handlers to where they are initially weakly defined in startup_stm32f4xxxx.s
62+
*/
63+
void ensure_interrupt_linkage(void);
5964
/* USER CODE BEGIN EFP */
6065

6166
/* USER CODE END EFP */

0 commit comments

Comments
 (0)