Commit 85e11a1a authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

use inline functions for most gpio

parent 044ff708
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -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) {
+33 −4
Original line number Diff line number Diff line
#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;
+0 −20
Original line number Diff line number Diff line
#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;
+0 −40
Original line number Diff line number Diff line
#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;