+/rtos

git clone https://git.julia.blue/+/rtos

Joseph RyanClean up OS interface/docs8216c9a

master
1.4 KiB45 linesraw
1#include "OS.h"
2#include "timer.h"
3#include "tivaware/gpio.h"
4#include "tivaware/hw_gpio.h"
5#include "tivaware/hw_ints.h"
6#include "tivaware/hw_memmap.h"
7#include "tivaware/hw_types.h"
8#include "tivaware/pin_map.h"
9#include "tivaware/rom.h"
10#include "tivaware/sysctl.h"
11
12void launchpad_init(void) {
13    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
14    HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
15    HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 1;
16    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, 0xE);
17    ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, 0x11);
18    ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, 0x11, GPIO_STRENGTH_2MA,
19                         GPIO_PIN_TYPE_STD_WPU);
20}
21
22void enable_button_interupts(uint8_t priority) {
23    ROM_GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4,
24                       GPIO_RISING_EDGE);
25    HWREG(GPIO_PORTF_BASE + GPIO_O_IM) = 0x11;
26    ROM_IntPrioritySet(INT_GPIOF, priority << 5);
27    ROM_IntEnable(INT_GPIOF);
28}
29
30void led_toggle(uint8_t led) {
31    ROM_GPIOPinWrite(GPIO_PORTF_BASE, led,
32                     ~ROM_GPIOPinRead(GPIO_PORTF_BASE, led));
33}
34
35void led_write(uint8_t led, bool value) {
36    ROM_GPIOPinWrite(GPIO_PORTF_BASE, led, value ? led : 0);
37}
38
39bool left_switch(void) {
40    return !ROM_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4);
41}
42
43bool right_switch(void) {
44    return !ROM_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0);
45}