Koduino
gpio.h
1 
19 #ifndef _gpio_h_
20 #define _gpio_h_
21 
22 #include "types.h"
23 #include "wiring_constants.h"
24 
25 #ifdef __cplusplus
26 extern "C"{
27 #endif // __cplusplus
28 
29 
30 
35 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
36 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
37 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
38 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
39 
47 void digitalWrite(uint8_t pin, LogicValue val);
48 
56 static inline uint8_t digitalRead(uint8_t pin) __attribute__((always_inline, unused));
57 static inline uint8_t digitalRead(uint8_t pin) {
58  return GPIO_ReadInputDataBit(PIN_MAP[pin].port, 1<<PIN_MAP[pin].pin);
59 }
60 
63 typedef enum DigitalPolarity {
64  ACTIVE_HIGH, ACTIVE_LOW
65 } DigitalPolarity;
66 
67 typedef enum LEDOutputMode {
68  LED_DIGITAL, LED_PWM
69 } LEDOutputMode;
70 
71 void ledInit(uint8_t name, DigitalPolarity polarity, LEDOutputMode mode);
72 // If it was inited as digital, then cast to 0 or 1. If it was inited as PWM, then this is interpreted as a "brightness" value in [0,1]
73 void ledWrite(uint8_t name, float val);
74 
75 // Use Red,Yellow,Green LEDs as a bargraph with three thresholds
76 void ledConfigBarGraph(uint8_t green, uint8_t yellow, uint8_t red);
77 void ledBarGraph(float val, float tgreen, float tyellow, float tred);
78 
79 
80 #ifdef __cplusplus
81 } // extern "C"
82 #endif // __cplusplus
83 
84 #endif
85 
Definition: types.h:108
static uint8_t digitalRead(uint8_t pin) __attribute__((always_inline
Read a digital pin.
Definition: gpio.h:57
void digitalWrite(uint8_t pin, LogicValue val)
Set a digital pin to a given logic level.
Definition: gpio.c:26