Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Committer:
Michael J. Spencer
Date:
Fri Feb 28 18:52:52 2014 -0800
Revision:
2:1df0b61d3b5a
Parent:
1:ab59fc9af055
Child:
3:f151d08d335c
Update to latest Smoothie.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scachat 0:31e91bb0ef3c 1 #ifndef PIN_H
scachat 0:31e91bb0ef3c 2 #define PIN_H
scachat 0:31e91bb0ef3c 3
scachat 0:31e91bb0ef3c 4 #include <stdlib.h>
Michael J. Spencer 2:1df0b61d3b5a 5 #include <stdio.h>
scachat 0:31e91bb0ef3c 6 #include <string>
scachat 0:31e91bb0ef3c 7
Michael J. Spencer 2:1df0b61d3b5a 8 #include "libs/LPC17xx/sLPC17xx.h" // smoothed mbed.h lib
Michael J. Spencer 2:1df0b61d3b5a 9
Michael J. Spencer 2:1df0b61d3b5a 10 class Pin {
scachat 0:31e91bb0ef3c 11 public:
Michael J. Spencer 2:1df0b61d3b5a 12 Pin();
Michael J. Spencer 2:1df0b61d3b5a 13
Michael J. Spencer 2:1df0b61d3b5a 14 Pin* from_string(std::string value);
Michael J. Spencer 2:1df0b61d3b5a 15
Michael J. Spencer 2:1df0b61d3b5a 16 inline bool connected(){
Michael J. Spencer 2:1df0b61d3b5a 17 return this->pin < 32;
Michael J. Spencer 2:1df0b61d3b5a 18 }
scachat 0:31e91bb0ef3c 19
Michael J. Spencer 2:1df0b61d3b5a 20 inline Pin* as_output(){
Michael J. Spencer 2:1df0b61d3b5a 21 if (this->pin < 32)
Michael J. Spencer 2:1df0b61d3b5a 22 this->port->FIODIR |= 1<<this->pin;
Michael J. Spencer 2:1df0b61d3b5a 23 return this;
Michael J. Spencer 2:1df0b61d3b5a 24 }
Michael J. Spencer 2:1df0b61d3b5a 25
Michael J. Spencer 2:1df0b61d3b5a 26 inline Pin* as_input(){
Michael J. Spencer 2:1df0b61d3b5a 27 if (this->pin < 32)
Michael J. Spencer 2:1df0b61d3b5a 28 this->port->FIODIR &= ~(1<<this->pin);
scachat 0:31e91bb0ef3c 29 return this;
scachat 0:31e91bb0ef3c 30 }
scachat 0:31e91bb0ef3c 31
Michael J. Spencer 2:1df0b61d3b5a 32 Pin* as_open_drain(void);
Michael J. Spencer 2:1df0b61d3b5a 33
Michael J. Spencer 2:1df0b61d3b5a 34 Pin* as_repeater(void);
Michael J. Spencer 2:1df0b61d3b5a 35
Michael J. Spencer 2:1df0b61d3b5a 36 Pin* pull_up(void);
scachat 0:31e91bb0ef3c 37
Michael J. Spencer 2:1df0b61d3b5a 38 Pin* pull_down(void);
Michael J. Spencer 2:1df0b61d3b5a 39
Michael J. Spencer 2:1df0b61d3b5a 40 Pin* pull_none(void);
scachat 0:31e91bb0ef3c 41
Michael J. Spencer 2:1df0b61d3b5a 42 inline bool get(){
Michael J. Spencer 2:1df0b61d3b5a 43
Michael J. Spencer 2:1df0b61d3b5a 44 if (this->pin >= 32) return false;
Michael J. Spencer 2:1df0b61d3b5a 45 return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1);
scachat 0:31e91bb0ef3c 46 }
scachat 0:31e91bb0ef3c 47
Michael J. Spencer 2:1df0b61d3b5a 48 inline void set(bool value)
Michael J. Spencer 2:1df0b61d3b5a 49 {
Michael J. Spencer 2:1df0b61d3b5a 50 if (this->pin >= 32) return;
Michael J. Spencer 2:1df0b61d3b5a 51 if ( this->inverting ^ value )
Michael J. Spencer 2:1df0b61d3b5a 52 this->port->FIOSET = 1 << this->pin;
Michael J. Spencer 2:1df0b61d3b5a 53 else
Michael J. Spencer 2:1df0b61d3b5a 54 this->port->FIOCLR = 1 << this->pin;
scachat 0:31e91bb0ef3c 55 }
scachat 0:31e91bb0ef3c 56
Michael J. Spencer 2:1df0b61d3b5a 57 LPC_GPIO_TypeDef* port;
Michael J. Spencer 2:1df0b61d3b5a 58 bool inverting;
Michael J. Spencer 2:1df0b61d3b5a 59 char port_number;
Michael J. Spencer 2:1df0b61d3b5a 60 unsigned char pin;
scachat 0:31e91bb0ef3c 61 };
scachat 0:31e91bb0ef3c 62
Michael J. Spencer 2:1df0b61d3b5a 63
Michael J. Spencer 2:1df0b61d3b5a 64
Michael J. Spencer 2:1df0b61d3b5a 65
scachat 0:31e91bb0ef3c 66 #endif