Skip to content

Commit 28243f1

Browse files
committed
Add new functions to find a PinName for a specific peripheral.
Usage example: PinNamepin_rx = pinmap_pin(USART1, PinMap_UART_RX); PinNamepin_tx = pinmap_pin(USART1, PinMap_UART_TX); Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent 90d3863 commit 28243f1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

cores/arduino/stm32/pinmap.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ void* pinmap_peripheral(PinName pin, const PinMap* map) {
3636
return peripheral;
3737
}
3838

39+
PinName pinmap_find_pin(void* peripheral, const PinMap* map) {
40+
while (map->peripheral != NP) {
41+
if (map->peripheral == peripheral)
42+
return map->pin;
43+
map++;
44+
}
45+
return NC;
46+
}
47+
48+
PinName pinmap_pin(void* peripheral, const PinMap* map) {
49+
PinName pin = NC;
50+
51+
if (peripheral != NP) {
52+
pin = pinmap_find_pin(peripheral, map);
53+
}
54+
// else error("pinmap not found for pin");
55+
return pin;
56+
}
57+
3958
uint32_t pinmap_find_function(PinName pin, const PinMap* map) {
4059
while (map->pin != NC) {
4160
if (map->pin == pin)

cores/arduino/stm32/pinmap.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ void pin_function(PinName pin, int function);
4141

4242
PinName pin_pinName(const PinMap* map);
4343

44-
void* pinmap_peripheral(PinName pin, const PinMap* map);
45-
uint32_t pinmap_function(PinName pin, const PinMap* map);
4644
void* pinmap_find_peripheral(PinName pin, const PinMap* map);
45+
void* pinmap_peripheral(PinName pin, const PinMap* map);
46+
PinName pinmap_find_pin(void* peripheral, const PinMap* map);
47+
PinName pinmap_pin(void* peripheral, const PinMap* map);
4748
uint32_t pinmap_find_function(PinName pin, const PinMap* map);
49+
uint32_t pinmap_function(PinName pin, const PinMap* map);
4850
void* pinmap_merge_peripheral(void* a, void* b);
4951

5052
#ifdef __cplusplus

0 commit comments

Comments
 (0)