Libraries and Example of mbed parallel bus using I2C port expanders

Dependencies:   HDSP253X mbed PCF8574_Bus

Committer:
wim
Date:
Sun Jan 25 17:30:47 2015 +0000
Revision:
6:aaefa04f06be
Parent:
2:1dab1089c332
Converted code for HDSP253X into Lib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 2:1dab1089c332 1 /* MBED_ControlBus - Use MBED Port Pins for controlling the external Bus
wim 2:1dab1089c332 2 * Copyright (c) 2011 Wim Huiskamp
wim 2:1dab1089c332 3 *
wim 2:1dab1089c332 4 * Released under the MIT License: http://mbed.org/license/mit
wim 2:1dab1089c332 5 *
wim 2:1dab1089c332 6 * version 0.2 Initial Release
wim 2:1dab1089c332 7 */
wim 2:1dab1089c332 8 #include "mbed.h"
wim 2:1dab1089c332 9 #include "MBED_ControlBus.h"
wim 2:1dab1089c332 10
wim 2:1dab1089c332 11
wim 2:1dab1089c332 12 /** Create an MBED_ControlBus object connected to the specified Pins
wim 2:1dab1089c332 13 *
wim 2:1dab1089c332 14 * @param PinName WR the Write pin
wim 2:1dab1089c332 15 * @param PinName RD the Read pin
wim 2:1dab1089c332 16 * @param PinName DTR the databuffer Transmit/Receive direction pin
wim 2:1dab1089c332 17 * @param PinName CDBUF the databuffer enable pin
wim 2:1dab1089c332 18 * @param PinName CDINT the Keyboard interrupt pin
wim 2:1dab1089c332 19 */
wim 6:aaefa04f06be 20 MBED_ControlBus::MBED_ControlBus(PinName WR, PinName RD, PinName DTR, PinName CDBUF, PinName CDINT) :
wim 2:1dab1089c332 21 _WR(WR), // WR pin
wim 2:1dab1089c332 22 _RD(RD), // RD pin
wim 2:1dab1089c332 23 _DTR(DTR), // DTR pin
wim 2:1dab1089c332 24 _CDBUF(CDBUF), // CDBUF pin
wim 6:aaefa04f06be 25 _CDINT(CDINT){ // CDINT pin
wim 2:1dab1089c332 26 _init();
wim 2:1dab1089c332 27 }
wim 2:1dab1089c332 28
wim 2:1dab1089c332 29
wim 2:1dab1089c332 30 /** Set or Clear the WR pin on Control Bus
wim 2:1dab1089c332 31 *
wim 2:1dab1089c332 32 * @param Bit_Level wr_level
wim 2:1dab1089c332 33 */
wim 2:1dab1089c332 34 void MBED_ControlBus::WR (Bit_Level wr_level) {
wim 2:1dab1089c332 35
wim 2:1dab1089c332 36 if (wr_level == LOW) {
wim 2:1dab1089c332 37 // Make sure that databus buffer is enabled for Write
wim 2:1dab1089c332 38 //busctrl(ENABLE, WRITE);
wim 2:1dab1089c332 39
wim 2:1dab1089c332 40 _RD = 1; // RD Pin High, make sure there is no collision
wim 2:1dab1089c332 41 _WR = 0; // WR Pin Low
wim 2:1dab1089c332 42 }
wim 2:1dab1089c332 43 else {
wim 2:1dab1089c332 44 _WR = 1; // WR Pin High
wim 2:1dab1089c332 45 }
wim 2:1dab1089c332 46 }
wim 2:1dab1089c332 47
wim 2:1dab1089c332 48
wim 2:1dab1089c332 49 /** Set or Clear the RD pin on Control Bus
wim 2:1dab1089c332 50 *
wim 2:1dab1089c332 51 * @param Bit_Level rd_level
wim 2:1dab1089c332 52 */
wim 2:1dab1089c332 53 void MBED_ControlBus::RD (Bit_Level rd_level) {
wim 2:1dab1089c332 54
wim 2:1dab1089c332 55 if (rd_level == LOW) {
wim 2:1dab1089c332 56 // Make sure that databus buffer is enabled for Read
wim 2:1dab1089c332 57 //busctrl(ENABLE, READ);
wim 2:1dab1089c332 58
wim 2:1dab1089c332 59 _WR = 1; // WR Pin High, make sure there is no collision
wim 2:1dab1089c332 60 _RD = 0; // RD Pin Low
wim 2:1dab1089c332 61 }
wim 2:1dab1089c332 62 else {
wim 2:1dab1089c332 63 _RD = 1; // RD Pin High
wim 2:1dab1089c332 64 }
wim 2:1dab1089c332 65 }
wim 2:1dab1089c332 66
wim 2:1dab1089c332 67
wim 2:1dab1089c332 68 /** Enable databus buffer for Write or Read
wim 2:1dab1089c332 69 *
wim 2:1dab1089c332 70 * @param Bus_Dir buf_dir
wim 2:1dab1089c332 71 */
wim 2:1dab1089c332 72 void MBED_ControlBus::busdir (Bus_Dir buf_dir) {
wim 2:1dab1089c332 73
wim 2:1dab1089c332 74 if (buf_dir == READ) {
wim 2:1dab1089c332 75 // Make sure that databus buffer is enabled for READ
wim 2:1dab1089c332 76 _DTR = 0; // DTR Pin Low, Read Direction
wim 2:1dab1089c332 77 _CDBUF = 0; // CDBUF Pin Low, Enable Buffer
wim 2:1dab1089c332 78 }
wim 2:1dab1089c332 79 else {
wim 2:1dab1089c332 80 // Make sure that databus buffer is enabled for Write
wim 2:1dab1089c332 81 _DTR = 1; // DTR Pin High, Write Direction
wim 2:1dab1089c332 82 _CDBUF = 0; // CDBUF Pin Low, Enable Buffer
wim 2:1dab1089c332 83 }
wim 2:1dab1089c332 84 }
wim 2:1dab1089c332 85
wim 2:1dab1089c332 86
wim 2:1dab1089c332 87 /** Enable/Disable databus buffer and control Write or Read Direction
wim 2:1dab1089c332 88 *
wim 2:1dab1089c332 89 * @param Bus_Ena buf_ena
wim 2:1dab1089c332 90 * @param Bus_Dir buf_dir
wim 2:1dab1089c332 91 */
wim 2:1dab1089c332 92 void MBED_ControlBus::busctrl (Bus_Ena buf_ena, Bus_Dir buf_dir) {
wim 2:1dab1089c332 93
wim 2:1dab1089c332 94 if (buf_ena == ENABLE) {
wim 2:1dab1089c332 95 _CDBUF = 0; // CDBUF Pin Low, Enable Buffer
wim 2:1dab1089c332 96 }
wim 2:1dab1089c332 97 else {
wim 2:1dab1089c332 98 _CDBUF = 1; // CDBUF Pin High, Disable Buffer
wim 2:1dab1089c332 99 }
wim 2:1dab1089c332 100
wim 2:1dab1089c332 101 if (buf_dir == READ) {
wim 2:1dab1089c332 102 _DTR = 0; // DTR Pin Low, Read Direction
wim 2:1dab1089c332 103 }
wim 2:1dab1089c332 104 else {
wim 2:1dab1089c332 105 _DTR = 1; // DTR Pin High, Write Direction
wim 2:1dab1089c332 106 }
wim 2:1dab1089c332 107 }
wim 2:1dab1089c332 108
wim 2:1dab1089c332 109
wim 2:1dab1089c332 110 /** Get the CDINT pin value from Control Bus
wim 2:1dab1089c332 111 *
wim 2:1dab1089c332 112 * @returns Bit_Level CDINT_level
wim 2:1dab1089c332 113 */
wim 2:1dab1089c332 114 Bit_Level MBED_ControlBus::CDINT () {
wim 2:1dab1089c332 115
wim 2:1dab1089c332 116 // CDINT Pin value, used as regular Pin rather than as interrupt
wim 2:1dab1089c332 117 if (_CDINT == 0)
wim 2:1dab1089c332 118 return LOW;
wim 2:1dab1089c332 119 else
wim 2:1dab1089c332 120 return HIGH;
wim 2:1dab1089c332 121 }
wim 2:1dab1089c332 122
wim 2:1dab1089c332 123
wim 2:1dab1089c332 124 /** Init MBED_ControlBus
wim 2:1dab1089c332 125 * @param
wim 2:1dab1089c332 126 * @returns
wim 2:1dab1089c332 127 */
wim 2:1dab1089c332 128 void MBED_ControlBus::_init() {
wim 2:1dab1089c332 129 // Make sure that all Control pins are disabled
wim 2:1dab1089c332 130 _RD = 1; // RD Pin High
wim 2:1dab1089c332 131 _WR = 1; // WR Pin High
wim 2:1dab1089c332 132
wim 2:1dab1089c332 133 // Make sure that databus buffer is enabled for Write
wim 2:1dab1089c332 134 busctrl(ENABLE, WRITE);
wim 2:1dab1089c332 135
wim 2:1dab1089c332 136 }