Home - fweiss/tm4c-led-pwm GitHub Wiki
An intuitive HAL for a TI tm4c123g MCU
A peripheral's registers are typically refered to via symbolic names. The names are typically acronyms.
For example, here is a symbolic register used in the example MCU: GPIODIR
. This symbol represents:
- GPIO Direction (used to select the input output mode of a GPIO pin)
- an offset in a block of addresses for the port
- a macro for read/write access to the register
Can C++ be used to make a more intuitive low-level API without sacrificing run-time efficiency?
Comparisons
[1] Direct register
GPIO_DIR(GPIOF) |= GPIO2;
[2] Object
DigitalPin<PortF, Pin2> pin;
pin.outputEnable = true;
The notable differences between [1] and [2] are:
GPIO_DIR
vsoutputEnable
GPIOF
vs 'PortF``GPIO2
vsPin2
|=
vs= true
Form [1] requires referring to the libcm4 macros and the tm4c data sheet. Form [2] almost fluently reads "For pin 2 on port F, enable output".
libopencm3
Here is the code ladder for a particular lobopencm3 function:
gpio_set(RGB_PORT, LED_G);
...
static inline void gpio_write(uint32_t gpioport, uint8_t gpios, uint8_t data)
...
#define GPIO_DIR(port) MMIO32((port) + 0x400)
...
#define MMIO16(addr) (*(volatile uint16_t *)(addr))