mbed base bard check program for BlueTooth USB dongle module (3 switches, 6 leds, I2C LCD, A/D)

Dependencies:   USBHost mbed

Fork of BTstack by Norimasa Okamoto

Committer:
tamaki
Date:
Mon Oct 17 00:25:18 2016 +0000
Revision:
3:7b7d1273e2d5
mbed base bard check program
; for BlueTooth USB dongle module
; (3 switches, 6 leds, I2C LCD, A/D)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tamaki 3:7b7d1273e2d5 1 /* An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01
tamaki 3:7b7d1273e2d5 2 * Copyright 2013, Takuo WATANABE (wtakuo)
tamaki 3:7b7d1273e2d5 3 *
tamaki 3:7b7d1273e2d5 4 * Licensed under the Apache License, Version 2.0 (the "License");
tamaki 3:7b7d1273e2d5 5 * you may not use this file except in compliance with the License.
tamaki 3:7b7d1273e2d5 6 * You may obtain a copy of the License at
tamaki 3:7b7d1273e2d5 7 *
tamaki 3:7b7d1273e2d5 8 * http://www.apache.org/licenses/LICENSE-2.0
tamaki 3:7b7d1273e2d5 9 *
tamaki 3:7b7d1273e2d5 10 * Unless required by applicable law or agreed to in writing, software
tamaki 3:7b7d1273e2d5 11 * distributed under the License is distributed on an "AS IS" BASIS,
tamaki 3:7b7d1273e2d5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tamaki 3:7b7d1273e2d5 13 * See the License for the specific language governing permissions and
tamaki 3:7b7d1273e2d5 14 * limitations under the License.
tamaki 3:7b7d1273e2d5 15 */
tamaki 3:7b7d1273e2d5 16
tamaki 3:7b7d1273e2d5 17 #ifndef ACM1602NI_H
tamaki 3:7b7d1273e2d5 18 #define ACM1602NI_H
tamaki 3:7b7d1273e2d5 19
tamaki 3:7b7d1273e2d5 20 #include "mbed.h"
tamaki 3:7b7d1273e2d5 21
tamaki 3:7b7d1273e2d5 22 /** An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01.
tamaki 3:7b7d1273e2d5 23 * The device does not work with default I2C library due to its slow I2C responce.
tamaki 3:7b7d1273e2d5 24 * This library adds some extra waits so that the device can answer to the I2C commands.
tamaki 3:7b7d1273e2d5 25 * The interface is basically the same as TextLCD by Simon Ford.
tamaki 3:7b7d1273e2d5 26 *
tamaki 3:7b7d1273e2d5 27 * @code
tamaki 3:7b7d1273e2d5 28 * #include "mbed.h"
tamaki 3:7b7d1273e2d5 29 * #include "ACM1602NI.h"
tamaki 3:7b7d1273e2d5 30 *
tamaki 3:7b7d1273e2d5 31 * // p9: sda, p10: scl
tamaki 3:7b7d1273e2d5 32 * ACM1602NI lcd(p9, p10);
tamaki 3:7b7d1273e2d5 33 *
tamaki 3:7b7d1273e2d5 34 * int main() {
tamaki 3:7b7d1273e2d5 35 * lcd.printf("Hello, World!\n");
tamaki 3:7b7d1273e2d5 36 * lcd.printf("ACM1602NI\n");
tamaki 3:7b7d1273e2d5 37 * }
tamaki 3:7b7d1273e2d5 38 * @endcode
tamaki 3:7b7d1273e2d5 39 */
tamaki 3:7b7d1273e2d5 40 class ACM1602NI : public Stream
tamaki 3:7b7d1273e2d5 41 {
tamaki 3:7b7d1273e2d5 42 public:
tamaki 3:7b7d1273e2d5 43 /** Create an ACM1602NI object connected to the specified I2C pins.
tamaki 3:7b7d1273e2d5 44 *
tamaki 3:7b7d1273e2d5 45 * @param sda The I2C data pin
tamaki 3:7b7d1273e2d5 46 * @param scl The I2C clock pin
tamaki 3:7b7d1273e2d5 47 */
tamaki 3:7b7d1273e2d5 48 ACM1602NI(PinName sda, PinName scl);
tamaki 3:7b7d1273e2d5 49
tamaki 3:7b7d1273e2d5 50 /** Create an ACM1602NI object connected to the specified I2C port.
tamaki 3:7b7d1273e2d5 51 *
tamaki 3:7b7d1273e2d5 52 * @param i2c The I2C port to connect to
tamaki 3:7b7d1273e2d5 53 */
tamaki 3:7b7d1273e2d5 54 ACM1602NI(I2C &i2c);
tamaki 3:7b7d1273e2d5 55
tamaki 3:7b7d1273e2d5 56 /** Initialize the device and clear screen
tamaki 3:7b7d1273e2d5 57 */
tamaki 3:7b7d1273e2d5 58 void init();
tamaki 3:7b7d1273e2d5 59
tamaki 3:7b7d1273e2d5 60 /** Locate to a screen column and row
tamaki 3:7b7d1273e2d5 61 *
tamaki 3:7b7d1273e2d5 62 * @param column The horizontal position from the left, indexed from 0
tamaki 3:7b7d1273e2d5 63 * @param row The vertical position from the top, indexed from 0
tamaki 3:7b7d1273e2d5 64 */
tamaki 3:7b7d1273e2d5 65 void locate(int column, int row);
tamaki 3:7b7d1273e2d5 66
tamaki 3:7b7d1273e2d5 67 /** Clear the screen and locate to 0,0 */
tamaki 3:7b7d1273e2d5 68 void cls();
tamaki 3:7b7d1273e2d5 69
tamaki 3:7b7d1273e2d5 70 int rows();
tamaki 3:7b7d1273e2d5 71 int columns();
tamaki 3:7b7d1273e2d5 72
tamaki 3:7b7d1273e2d5 73 protected:
tamaki 3:7b7d1273e2d5 74 virtual int _putc(int value);
tamaki 3:7b7d1273e2d5 75 virtual int _getc();
tamaki 3:7b7d1273e2d5 76
tamaki 3:7b7d1273e2d5 77 int address(int column, int raw);
tamaki 3:7b7d1273e2d5 78 void character(int column, int row, int c);
tamaki 3:7b7d1273e2d5 79 int writeBytes(const char *data, int length, bool repeated = false);
tamaki 3:7b7d1273e2d5 80 void writeCommand(int command);
tamaki 3:7b7d1273e2d5 81 void writeData(int data);
tamaki 3:7b7d1273e2d5 82
tamaki 3:7b7d1273e2d5 83 static const int i2c_addr = 0x50 << 1;
tamaki 3:7b7d1273e2d5 84 static const int i2c_bit_wait_us = 20;
tamaki 3:7b7d1273e2d5 85 static const int i2c_command_wait_ms = 4;
tamaki 3:7b7d1273e2d5 86
tamaki 3:7b7d1273e2d5 87 static const int display_columns = 16;
tamaki 3:7b7d1273e2d5 88 static const int display_rows = 2;
tamaki 3:7b7d1273e2d5 89
tamaki 3:7b7d1273e2d5 90 I2C _i2c;
tamaki 3:7b7d1273e2d5 91 int _column, _row;
tamaki 3:7b7d1273e2d5 92 };
tamaki 3:7b7d1273e2d5 93
tamaki 3:7b7d1273e2d5 94 #endif
tamaki 3:7b7d1273e2d5 95