[175] | 1 | /*
|
---|
| 2 | ****************************************************************************
|
---|
| 3 | * This file is part of Arduino Lucky Shield Library
|
---|
| 4 | *
|
---|
| 5 | * Copyright (c) 2016 Arduino srl. All right reserved.
|
---|
| 6 | *
|
---|
| 7 | * File : CAT9555.h
|
---|
| 8 | * Date : 2016/03/21
|
---|
| 9 | * Revision : 0.0.1 $
|
---|
| 10 | * Author: andrea[at]arduino[dot]org
|
---|
| 11 | *
|
---|
| 12 | ****************************************************************************
|
---|
| 13 |
|
---|
| 14 | This library is free software; you can redistribute it and/or
|
---|
| 15 | modify it under the terms of the GNU Lesser General Public
|
---|
| 16 | License as published by the Free Software Foundation; either
|
---|
| 17 | version 2.1 of the License, or (at your option) any later version.
|
---|
| 18 |
|
---|
| 19 | This library is distributed in the hope that it will be useful,
|
---|
| 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 22 | Lesser General Public License for more details.
|
---|
| 23 |
|
---|
| 24 | You should have received a copy of the GNU Lesser General Public
|
---|
| 25 | License along with this library; if not, write to the Free Software
|
---|
| 26 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
| 27 |
|
---|
| 28 | ******************************************************************************/
|
---|
| 29 |
|
---|
| 30 | #ifndef CAT9555_h
|
---|
| 31 | #define CAT9555_h
|
---|
| 32 |
|
---|
| 33 | #include <Arduino.h>
|
---|
| 34 |
|
---|
| 35 | ///////////////////////////////////
|
---|
| 36 | // CAT9555 Register Definitions //
|
---|
| 37 | ///////////////////////////////////
|
---|
| 38 |
|
---|
| 39 | #define INPUT_PORT0 (uint8_t)0x00
|
---|
| 40 | #define INPUT_PORT1 (uint8_t)0x01
|
---|
| 41 | #define OUTPUT_PORT0 (uint8_t)0x02
|
---|
| 42 | #define OUTPUT_PORT1 (uint8_t)0x03
|
---|
| 43 | #define POLARITY_PORT0 (uint8_t)0x04
|
---|
| 44 | #define POLARITY_PORT1 (uint8_t)0x05
|
---|
| 45 | #define CONFIG_PORT0 (uint8_t)0x06
|
---|
| 46 | #define CONFIG_PORT1 (uint8_t)0x07
|
---|
| 47 | #define ADDRESS (uint8_t)0x20
|
---|
| 48 |
|
---|
| 49 | ///////////////////////////////////
|
---|
| 50 | // CAT9555 PIN Definitions //
|
---|
| 51 | ///////////////////////////////////
|
---|
| 52 |
|
---|
| 53 | #define PIR (uint16_t)0x800 //reg0
|
---|
| 54 | #define LED1 (uint16_t)0x1000 //reg0
|
---|
| 55 | #define LED2 (uint16_t)0x2000 //reg0
|
---|
| 56 | #define REL1 (uint16_t)0x4000 //reg0
|
---|
| 57 | #define REL2 (uint16_t)0x8000 //reg0
|
---|
| 58 | #define ACC (uint16_t)0x0100 //reg0
|
---|
| 59 | #define JOYL (uint8_t)0X04 //reg1
|
---|
| 60 | #define JOYR (uint8_t)0X08 //reg1
|
---|
| 61 | #define JOYU (uint8_t)0X01 //reg1
|
---|
| 62 | #define JOYD (uint8_t)0X02 //reg1
|
---|
| 63 | #define JOYC (uint8_t)0X10 //reg1
|
---|
| 64 | #define PB1 (uint8_t)0x20 //reg1
|
---|
| 65 | #define PB2 (uint8_t)0x40 //reg1
|
---|
| 66 | #define OLEDR (uint8_t)0x80 //reg1
|
---|
| 67 |
|
---|
| 68 | ////////////////////////////////
|
---|
| 69 | // CAT9555 Class Declaration //
|
---|
| 70 | ////////////////////////////////
|
---|
| 71 | class CAT9555
|
---|
| 72 | {
|
---|
| 73 | public:
|
---|
| 74 | CAT9555(uint8_t addr = ADDRESS);
|
---|
| 75 | void begin();
|
---|
| 76 | int digitalRead(int pin);
|
---|
| 77 | void digitalWrite(int pin, int value);
|
---|
| 78 |
|
---|
| 79 | private:
|
---|
| 80 | byte address;
|
---|
| 81 | void writeRegister(int reg, int data);
|
---|
| 82 | uint8_t read_8_Register(int reg);
|
---|
| 83 | uint16_t read_16_Register(int reg);
|
---|
| 84 | };
|
---|
| 85 |
|
---|
| 86 | extern CAT9555 cat9555;
|
---|
| 87 |
|
---|
| 88 | #endif
|
---|