Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Lpc17xx40xxGPIO.hxx
Go to the documentation of this file.
1
36#ifndef _FREERTOS_DRIVERS_NXP_LPC17XX40XXGPIO_HXX_
37#define _FREERTOS_DRIVERS_NXP_LPC17XX40XXGPIO_HXX_
38
39#include "chip.h"
40#include "core_cm3.h"
41#include "gpio_17xx_40xx.h"
42#include "iocon_17xx_40xx.h"
43#include "os/Gpio.hxx"
44#include "GpioWrapper.hxx"
45
49template <uint8_t PORT, uint8_t PIN> struct LpcGpioPin
50{
52 static constexpr uint8_t port()
53 {
54 return PORT;
55 }
57 static constexpr uint8_t pin()
58 {
59 return PIN;
60 }
62 static void set(bool value)
63 {
64 Chip_GPIO_SetPinState(LPC_GPIO, port(), pin(), value);
65 }
67 static void toggle()
68 {
69 Chip_GPIO_SetPinToggle(LPC_GPIO, port(), pin());
70 }
73 static bool get()
74 {
75 return Chip_GPIO_GetPinState(LPC_GPIO, port(), pin());
76 }
77
80 static constexpr const Gpio *instance()
81 {
83 }
84
86 static bool is_output()
87 {
88 return Chip_GPIO_GetPinDIR(LPC_GPIO, port(), pin());
89 }
90
91protected:
93 static void set_output()
94 {
95 Chip_GPIO_SetPinDIROutput(LPC_GPIO, port(), pin());
96 }
98 static void set_input()
99 {
100 Chip_GPIO_SetPinDIRInput(LPC_GPIO, port(), pin());
101 }
102};
103
105template <class Defs, bool SAFE_VALUE> struct GpioOutputPin : public Defs
106{
107 using Defs::port;
108 using Defs::pin;
109 using Defs::set_output;
110 using Defs::set;
112 static void hw_init()
113 {
114 Chip_GPIO_Init(LPC_GPIO);
115 Chip_IOCON_Init(LPC_IOCON);
116 Chip_IOCON_PinMuxSet(
117 LPC_IOCON, port(), pin(), IOCON_FUNC0 | IOCON_MODE_INACT);
119 }
121 static void hw_set_to_safe()
122 {
123 set_output();
124 set(SAFE_VALUE);
125 }
126};
127
131template <class Defs>
132struct GpioOutputSafeLow : public GpioOutputPin<Defs, false>
133{
134};
135
139template <class Defs>
140struct GpioOutputSafeHigh : public GpioOutputPin<Defs, true>
141{
142};
143
148template <class Defs> struct LedPin : public GpioOutputPin<Defs, false>
149{
150};
151
153template <class Defs, uint32_t GPIO_PULL> struct GpioInputPin : public Defs
154{
155public:
156 using Defs::port;
157 using Defs::pin;
159 static void hw_init()
160 {
161 Chip_GPIO_Init(LPC_GPIO);
162 Chip_IOCON_Init(LPC_IOCON);
163 Chip_IOCON_PinMuxSet(LPC_IOCON, port(), pin(), IOCON_FUNC0 | GPIO_PULL);
164 }
166 static void hw_set_to_safe()
167 {
168 hw_init();
169 }
170};
171
175template <class Defs>
176struct GpioInputPU : public GpioInputPin<Defs, IOCON_MODE_PULLUP>
177{
178};
179
183template <class Defs>
184struct GpioInputPD : public GpioInputPin<Defs, IOCON_MODE_PULLDOWN>
185{
186};
187
191template <class Defs>
192struct GpioInputNP : public GpioInputPin<Defs, IOCON_MODE_INACT>
193{
194};
195
200template <class Defs>
201struct GpioInputRep : public GpioInputPin<Defs, IOCON_MODE_REPEATER>
202{
203};
204
222#define GPIO_PIN(NAME, BaseClass, PORT, NUM) \
223 typedef BaseClass<LpcGpioPin<PORT, NUM>> NAME##_Pin
224
225#endif // _FREERTOS_DRIVERS_NXP_LPC17XX40XXGPIO_HXX_
Creates an implementation of an os-independent Gpio object from a hardware-specific static Gpio struc...
OS-independent abstraction for GPIO.
Definition Gpio.hxx:43
Defines a GPIO input pin.
Defines a GPIO input pin with pull-down enabled.
Defines a GPIO input pin with pull-up.
Parametric GPIO input class.
static void hw_init()
Initializes the hardware pin.
static void hw_set_to_safe()
Sets the hardware pin to a safe state.
GPIO Input pin in repeater configuration (pull the same direction as sensed on the input).
Parametric GPIO output class.
static void hw_init()
Initializes the hardware pin.
static void set(bool value)
Sets the output pinm.
static void hw_set_to_safe()
Sets the hardware pin to a safe value.
Defines a GPIO output pin, initialized to be an output pin with high level.
Defines a GPIO output pin, initialized to be an output pin with low level.
Defines a GPIO output pin with high-current drive and low initialization level.
Static GPIO implementation for the NXP LPC microcontrollers.
static constexpr uint8_t pin()
static void toggle()
Toggles the output pin level.
static void set_input()
Configures pin as input.
static bool get()
static void set(bool value)
Sets the output pin to a given level.
static bool is_output()
static constexpr const Gpio * instance()
static void set_output()
Configures pin as output.
static constexpr uint8_t port()