Orignal AVR Tiny USI Based I2C slave Charlieplexing 7SEG LED Driver.
My7SEG.h@2:e7362bcb9e1f, 2013-12-12 (annotated)
- Committer:
- bant62
- Date:
- Thu Dec 12 00:35:39 2013 +0000
- Revision:
- 2:e7362bcb9e1f
- Parent:
- 0:1c9f9768e990
Fixed the software description;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bant62 | 0:1c9f9768e990 | 1 | /** |
bant62 | 0:1c9f9768e990 | 2 | ***************************************************************************** |
bant62 | 0:1c9f9768e990 | 3 | * File Name : My7SEG.h |
bant62 | 0:1c9f9768e990 | 4 | * |
bant62 | 0:1c9f9768e990 | 5 | * Title : ORGINAL I2C LCD Display Claass Header File |
bant62 | 0:1c9f9768e990 | 6 | * Revision : 0.1 |
bant62 | 0:1c9f9768e990 | 7 | * Notes : |
bant62 | 0:1c9f9768e990 | 8 | * Target Board : mbed NXP LPC1768, mbed LPC1114FN28 etc |
bant62 | 0:1c9f9768e990 | 9 | * Tool Chain : ???? |
bant62 | 0:1c9f9768e990 | 10 | * |
bant62 | 0:1c9f9768e990 | 11 | * Revision History: |
bant62 | 0:1c9f9768e990 | 12 | * When Who Description of change |
bant62 | 0:1c9f9768e990 | 13 | * ----------- ----------- ----------------------- |
bant62 | 2:e7362bcb9e1f | 14 | * 2013/12/06 Hiroshi M init |
bant62 | 0:1c9f9768e990 | 15 | ***************************************************************************** |
bant62 | 0:1c9f9768e990 | 16 | * |
bant62 | 0:1c9f9768e990 | 17 | * Copyright (C) 2013 Hiroshi M, MIT License |
bant62 | 0:1c9f9768e990 | 18 | * |
bant62 | 0:1c9f9768e990 | 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
bant62 | 0:1c9f9768e990 | 20 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
bant62 | 0:1c9f9768e990 | 21 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
bant62 | 0:1c9f9768e990 | 22 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
bant62 | 0:1c9f9768e990 | 23 | * furnished to do so, subject to the following conditions: |
bant62 | 0:1c9f9768e990 | 24 | * |
bant62 | 0:1c9f9768e990 | 25 | * The above copyright notice and this permission notice shall be included in all copies or |
bant62 | 0:1c9f9768e990 | 26 | * substantial portions of the Software. |
bant62 | 0:1c9f9768e990 | 27 | * |
bant62 | 0:1c9f9768e990 | 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
bant62 | 0:1c9f9768e990 | 29 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
bant62 | 0:1c9f9768e990 | 30 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
bant62 | 0:1c9f9768e990 | 31 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
bant62 | 0:1c9f9768e990 | 32 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
bant62 | 0:1c9f9768e990 | 33 | * |
bant62 | 0:1c9f9768e990 | 34 | **/ |
bant62 | 0:1c9f9768e990 | 35 | |
bant62 | 0:1c9f9768e990 | 36 | #ifndef __My7SEG_H_ |
bant62 | 0:1c9f9768e990 | 37 | #define __My7SEG_H_ |
bant62 | 0:1c9f9768e990 | 38 | |
bant62 | 0:1c9f9768e990 | 39 | /* Includes ----------------------------------------------------------------- */ |
bant62 | 0:1c9f9768e990 | 40 | #include "mbed.h" |
bant62 | 0:1c9f9768e990 | 41 | /* typedef ------------------------------------------------------------------ */ |
bant62 | 0:1c9f9768e990 | 42 | |
bant62 | 0:1c9f9768e990 | 43 | /* define ------------------------------------------------------------------- */ |
bant62 | 0:1c9f9768e990 | 44 | #define ESC 0x1B |
bant62 | 0:1c9f9768e990 | 45 | #define I2C_ADDR_MY7SEG 0x33 |
bant62 | 0:1c9f9768e990 | 46 | #define _i2cSUCCESS 0 |
bant62 | 0:1c9f9768e990 | 47 | #define _i2cFAILURE 1 |
bant62 | 0:1c9f9768e990 | 48 | |
bant62 | 0:1c9f9768e990 | 49 | /* macro -------------------------------------------------------------------- */ |
bant62 | 0:1c9f9768e990 | 50 | /* variables ---------------------------------------------------------------- */ |
bant62 | 0:1c9f9768e990 | 51 | /* class -------------------------------------------------------------------- */ |
bant62 | 0:1c9f9768e990 | 52 | class My7SEG |
bant62 | 0:1c9f9768e990 | 53 | { |
bant62 | 0:1c9f9768e990 | 54 | private: |
bant62 | 0:1c9f9768e990 | 55 | static const int i2c_addr = I2C_ADDR_MY7SEG << 1; |
bant62 | 0:1c9f9768e990 | 56 | static const int i2c_bit_wait_us = 20; |
bant62 | 0:1c9f9768e990 | 57 | static const int i2c_command_wait_ms = 4; |
bant62 | 0:1c9f9768e990 | 58 | |
bant62 | 0:1c9f9768e990 | 59 | I2C *_i2c; |
bant62 | 0:1c9f9768e990 | 60 | int writeBytes(const char *data, int length, bool repeated=false); |
bant62 | 0:1c9f9768e990 | 61 | |
bant62 | 0:1c9f9768e990 | 62 | protected: |
bant62 | 0:1c9f9768e990 | 63 | |
bant62 | 0:1c9f9768e990 | 64 | |
bant62 | 0:1c9f9768e990 | 65 | public: |
bant62 | 0:1c9f9768e990 | 66 | My7SEG(I2C *i2c); |
bant62 | 0:1c9f9768e990 | 67 | |
bant62 | 0:1c9f9768e990 | 68 | int clear(void); |
bant62 | 0:1c9f9768e990 | 69 | int shift_left(void); |
bant62 | 0:1c9f9768e990 | 70 | int shift_right(void); |
bant62 | 0:1c9f9768e990 | 71 | int rotato_left(void); |
bant62 | 0:1c9f9768e990 | 72 | int rotato_right(void); |
bant62 | 0:1c9f9768e990 | 73 | int printChar(char c); |
bant62 | 0:1c9f9768e990 | 74 | int printPosChar(int pos, char chr); |
bant62 | 0:1c9f9768e990 | 75 | int printStr(const char *s); |
bant62 | 0:1c9f9768e990 | 76 | |
bant62 | 0:1c9f9768e990 | 77 | }; |
bant62 | 0:1c9f9768e990 | 78 | |
bant62 | 0:1c9f9768e990 | 79 | #endif /* __My7SEG_H_ */ |