summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-01-11 08:55:15 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-01-11 08:55:15 +0100
commit85e11a1a460f08f1791a03a6bb95c976b7117ab8 (patch)
treede254068771592db8da8c06d641e9f09094efabe
parent044ff708d979cb5c17c1b2e0dafb6be0ccecab43 (diff)
use inline functions for most gpio
-rw-r--r--include/arduino-nano/driver/gpio.h16
-rw-r--r--include/msp430fr5969lp/driver/gpio.h37
-rw-r--r--src/arch/arduino-nano/driver/gpio.cc20
-rw-r--r--src/arch/msp430fr5969lp/driver/gpio.cc40
4 files changed, 45 insertions, 68 deletions
diff --git a/include/arduino-nano/driver/gpio.h b/include/arduino-nano/driver/gpio.h
index 17bdfc8..6acf977 100644
--- a/include/arduino-nano/driver/gpio.h
+++ b/include/arduino-nano/driver/gpio.h
@@ -36,10 +36,18 @@ class GPIO {
pd7 = 31
};
- void setup();
- void led_on(unsigned char id);
- void led_off(unsigned char id);
- void led_toggle(unsigned char id);
+ inline void setup() {
+ DDRB = _BV(PB5);
+ }
+ inline void led_on(unsigned char id) {
+ PORTB |= _BV(PB5);
+ }
+ inline void led_off(unsigned char id) {
+ PORTB &= ~_BV(PB5);
+ }
+ inline void led_toggle(unsigned char id) {
+ PINB = _BV(PB5);
+ }
inline void input(unsigned char const pin) {
if (pin < 8) {
} else if (pin < 16) {
diff --git a/include/msp430fr5969lp/driver/gpio.h b/include/msp430fr5969lp/driver/gpio.h
index 177e7c5..7ac3ba3 100644
--- a/include/msp430fr5969lp/driver/gpio.h
+++ b/include/msp430fr5969lp/driver/gpio.h
@@ -1,16 +1,45 @@
#ifndef GPIO_H
#define GPIO_H
+#include <msp430.h>
+
class GPIO {
private:
GPIO(const GPIO &copy);
public:
GPIO () {}
- void setup();
- void led_on(unsigned char id);
- void led_off(unsigned char id);
- void led_toggle(unsigned char id);
+ inline void setup() {
+ P1OUT = 0;
+ P2OUT = 0;
+ P3OUT = 0;
+ P4OUT = 0;
+ P1DIR = BIT0;
+ P2DIR = 0;
+ P3DIR = 0;
+ P4DIR = BIT6;
+ }
+ inline void led_on(unsigned char id) {
+ if (id == 0) {
+ P1OUT |= BIT0;
+ } else {
+ P4OUT |= BIT6;
+ }
+ }
+ inline void led_off(unsigned char id) {
+ if (id == 0) {
+ P1OUT &= ~BIT0;
+ } else {
+ P4OUT &= ~BIT6;
+ }
+ }
+ inline void led_toggle(unsigned char id) {
+ if (id == 0) {
+ P1OUT ^= BIT0;
+ } else {
+ P4OUT ^= BIT6;
+ }
+ }
};
extern GPIO gpio;
diff --git a/src/arch/arduino-nano/driver/gpio.cc b/src/arch/arduino-nano/driver/gpio.cc
index 66e24db..b1f9c63 100644
--- a/src/arch/arduino-nano/driver/gpio.cc
+++ b/src/arch/arduino-nano/driver/gpio.cc
@@ -1,24 +1,4 @@
#include "driver/gpio.h"
#include <avr/io.h>
-void GPIO::setup()
-{
- DDRB = _BV(PB5);
-}
-
-void GPIO::led_on(unsigned char id)
-{
- PORTB |= _BV(PB5);
-}
-
-void GPIO::led_off(unsigned char id)
-{
- PORTB &= ~_BV(PB5);
-}
-
-void GPIO::led_toggle(unsigned char id)
-{
- PINB = _BV(PB5);
-}
-
GPIO gpio;
diff --git a/src/arch/msp430fr5969lp/driver/gpio.cc b/src/arch/msp430fr5969lp/driver/gpio.cc
index e1179af..1403aed 100644
--- a/src/arch/msp430fr5969lp/driver/gpio.cc
+++ b/src/arch/msp430fr5969lp/driver/gpio.cc
@@ -1,43 +1,3 @@
#include "driver/gpio.h"
-#include <msp430.h>
-
-void GPIO::setup()
-{
- P1OUT = 0;
- P2OUT = 0;
- P3OUT = 0;
- P4OUT = 0;
- P1DIR = BIT0;
- P2DIR = 0;
- P3DIR = 0;
- P4DIR = BIT6;
-}
-
-void GPIO::led_on(unsigned char id)
-{
- if (id == 0) {
- P1OUT |= BIT0;
- } else {
- P4OUT |= BIT6;
- }
-}
-
-void GPIO::led_off(unsigned char id)
-{
- if (id == 0) {
- P1OUT &= ~BIT0;
- } else {
- P4OUT &= ~BIT6;
- }
-}
-
-void GPIO::led_toggle(unsigned char id)
-{
- if (id == 0) {
- P1OUT ^= BIT0;
- } else {
- P4OUT ^= BIT6;
- }
-}
GPIO gpio;