my implementation of mbed-like classes using the LPC1768 register access.

Dependents:   registers-example RedWireBridge

This is just to satisfy my curiosity on how the mbed libraries work. I put it here just in case others are too. Every time I learn how another internal register works, I'll keep it here to save myself from future coding headaches.

working

  • DigitalIn
  • DigitalOut
  • wait()

mostly working

  • Serial
  • Timer
  • Ticker
  • Timeout

Serial doesn't have all the methods that mbed had, but it works for me. (only UART0, so only over USB to the pc for now) Timer has the same limitations of mbed for default resolution (30 min limit), and if you start at the end of resolution and stop after it rolls back to 0, it doesn't take that into account. But I added the option to change resolution, so I can have longer timers.

For Ticker, I used a 100 microsecond timer instead of a 1 microsecond Timer, so the smallest interval in between function calls is 100 microseconds. (10KHz) However, this means that the maximum interval in between function calls is 59 hours. (untested)

The Timeout class, simply uses a Ticker, but then marks it as nonactive after the first function call. Automatically calls the detach() function when attaching it again, so no don't need to worry about it.

Committer:
elevatorguy
Date:
Thu Jan 03 05:25:18 2013 +0000
Revision:
2:276fb0fe230c
Parent:
0:d2d9baa1a6d8
fix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elevatorguy 0:d2d9baa1a6d8 1 #ifndef __INOUT_H_
elevatorguy 0:d2d9baa1a6d8 2 #define __INOUT_H_
elevatorguy 0:d2d9baa1a6d8 3
elevatorguy 0:d2d9baa1a6d8 4 #include "LPC17xx.h"
elevatorguy 0:d2d9baa1a6d8 5
elevatorguy 0:d2d9baa1a6d8 6 //useful constants to define
elevatorguy 0:d2d9baa1a6d8 7 #define PULLUP 0
elevatorguy 0:d2d9baa1a6d8 8 #define PULLDOWN 1
elevatorguy 0:d2d9baa1a6d8 9 #define PULLNONE 2
elevatorguy 0:d2d9baa1a6d8 10 #define KEEPER 3
elevatorguy 0:d2d9baa1a6d8 11 #define OUTPUT 1
elevatorguy 0:d2d9baa1a6d8 12 #define INPUT 0
elevatorguy 0:d2d9baa1a6d8 13 #define LED1 1
elevatorguy 0:d2d9baa1a6d8 14 #define LED2 2
elevatorguy 0:d2d9baa1a6d8 15 #define LED3 3
elevatorguy 0:d2d9baa1a6d8 16 #define LED4 4
elevatorguy 0:d2d9baa1a6d8 17 #define NULL 0
elevatorguy 0:d2d9baa1a6d8 18
elevatorguy 0:d2d9baa1a6d8 19 #define p5 5
elevatorguy 0:d2d9baa1a6d8 20 #define p6 6
elevatorguy 0:d2d9baa1a6d8 21 #define p7 7
elevatorguy 0:d2d9baa1a6d8 22 #define p8 8
elevatorguy 0:d2d9baa1a6d8 23 #define p9 9
elevatorguy 0:d2d9baa1a6d8 24 #define p10 10
elevatorguy 0:d2d9baa1a6d8 25 #define p11 11
elevatorguy 0:d2d9baa1a6d8 26 #define p12 12
elevatorguy 0:d2d9baa1a6d8 27 #define p13 13
elevatorguy 0:d2d9baa1a6d8 28 #define p14 14
elevatorguy 0:d2d9baa1a6d8 29 #define p15 15
elevatorguy 0:d2d9baa1a6d8 30 #define p16 16
elevatorguy 0:d2d9baa1a6d8 31 #define p17 17
elevatorguy 0:d2d9baa1a6d8 32 #define p18 18
elevatorguy 0:d2d9baa1a6d8 33 #define p19 19
elevatorguy 0:d2d9baa1a6d8 34 #define p20 20
elevatorguy 0:d2d9baa1a6d8 35 #define p21 21
elevatorguy 0:d2d9baa1a6d8 36 #define p22 22
elevatorguy 0:d2d9baa1a6d8 37 #define p23 23
elevatorguy 0:d2d9baa1a6d8 38 #define p24 24
elevatorguy 0:d2d9baa1a6d8 39 #define p25 25
elevatorguy 0:d2d9baa1a6d8 40 #define p26 26
elevatorguy 0:d2d9baa1a6d8 41 #define p27 27
elevatorguy 0:d2d9baa1a6d8 42 #define p28 28
elevatorguy 0:d2d9baa1a6d8 43 #define p29 29
elevatorguy 0:d2d9baa1a6d8 44 #define p30 30
elevatorguy 0:d2d9baa1a6d8 45
elevatorguy 0:d2d9baa1a6d8 46 class InOut
elevatorguy 0:d2d9baa1a6d8 47 {
elevatorguy 0:d2d9baa1a6d8 48 public: // char type if value never goes above 256
elevatorguy 0:d2d9baa1a6d8 49 char port; //the port number (ports 0, 1 or 2)
elevatorguy 0:d2d9baa1a6d8 50 char bit; //the bit of the port
elevatorguy 0:d2d9baa1a6d8 51 void write(bool); //bool because it can only be high or low
elevatorguy 0:d2d9baa1a6d8 52 bool read(); //bool because it can only be high or low
elevatorguy 0:d2d9baa1a6d8 53 InOut(char, bool); //contructor for pins (led or mbed pin #, and 1 for output or 0 for input)
elevatorguy 0:d2d9baa1a6d8 54 InOut(char, char, bool); // port, bit and 1 for output / 0 for input. This is for the pins that the mbed doesn't use
elevatorguy 0:d2d9baa1a6d8 55 void setDirection(bool); // the constructor calls this method, but we can call it too if we need to
elevatorguy 0:d2d9baa1a6d8 56 void mode(char); // PULLUP, PULLDOWN, PULLNONE or KEEPER (char because really we are only using 2 bits)
elevatorguy 0:d2d9baa1a6d8 57 InOut& operator=(bool); // so we can do led1 = 0; instead of led1.write(0); just like the mbed library does
elevatorguy 0:d2d9baa1a6d8 58 operator bool(); // so we can do "led1" instead of "led1.read()" just like the mbed library does
elevatorguy 0:d2d9baa1a6d8 59 void output(); //calls setDirection, to set bit to output
elevatorguy 0:d2d9baa1a6d8 60 void input(); //calls setDirection, to set bit to input
elevatorguy 0:d2d9baa1a6d8 61 };
elevatorguy 0:d2d9baa1a6d8 62
elevatorguy 0:d2d9baa1a6d8 63 #endif