Skip to content
Snippets Groups Projects
Commit 85e11a1a authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

use inline functions for most gpio

parent 044ff708
No related branches found
No related tags found
No related merge requests found
...@@ -36,10 +36,18 @@ class GPIO { ...@@ -36,10 +36,18 @@ class GPIO {
pd7 = 31 pd7 = 31
}; };
void setup(); inline void setup() {
void led_on(unsigned char id); DDRB = _BV(PB5);
void led_off(unsigned char id); }
void led_toggle(unsigned char id); 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) { inline void input(unsigned char const pin) {
if (pin < 8) { if (pin < 8) {
} else if (pin < 16) { } else if (pin < 16) {
......
#ifndef GPIO_H #ifndef GPIO_H
#define GPIO_H #define GPIO_H
#include <msp430.h>
class GPIO { class GPIO {
private: private:
GPIO(const GPIO &copy); GPIO(const GPIO &copy);
public: public:
GPIO () {} GPIO () {}
void setup(); inline void setup() {
void led_on(unsigned char id); P1OUT = 0;
void led_off(unsigned char id); P2OUT = 0;
void led_toggle(unsigned char id); 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; extern GPIO gpio;
......
#include "driver/gpio.h" #include "driver/gpio.h"
#include <avr/io.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; GPIO gpio;
#include "driver/gpio.h" #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; GPIO gpio;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment