Controll MCP23S17 as GPIO

Committer:
ryood
Date:
Wed Nov 02 09:15:21 2016 +0000
Revision:
7:3f853801cb6d
Parent:
6:1b3511093630
Child:
9:b0e9ec45a720
Impl. ExioMcp23s17Keypad4x4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryood 5:b82675c50720 1 /**
ryood 5:b82675c50720 2 * =============================================================================
ryood 5:b82675c50720 3 * Rotary Encoder class (Version 0.0.1)
ryood 5:b82675c50720 4 * =============================================================================
ryood 5:b82675c50720 5 * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
ryood 5:b82675c50720 6 *
ryood 5:b82675c50720 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
ryood 5:b82675c50720 8 * of this software and associated documentation files (the "Software"), to deal
ryood 5:b82675c50720 9 * in the Software without restriction, including without limitation the rights
ryood 5:b82675c50720 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ryood 5:b82675c50720 11 * copies of the Software, and to permit persons to whom the Software is
ryood 5:b82675c50720 12 * furnished to do so, subject to the following conditions:
ryood 5:b82675c50720 13 *
ryood 5:b82675c50720 14 * The above copyright notice and this permission notice shall be included in
ryood 5:b82675c50720 15 * all copies or substantial portions of the Software.
ryood 5:b82675c50720 16 *
ryood 5:b82675c50720 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ryood 5:b82675c50720 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ryood 5:b82675c50720 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ryood 5:b82675c50720 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ryood 5:b82675c50720 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ryood 5:b82675c50720 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ryood 5:b82675c50720 23 * THE SOFTWARE.
ryood 5:b82675c50720 24 * =============================================================================
ryood 5:b82675c50720 25 */
ryood 5:b82675c50720 26
ryood 5:b82675c50720 27 /*
ryood 5:b82675c50720 28 * 2016.11.02 Customized for MCP23S17 by rood
ryood 5:b82675c50720 29 */
ryood 5:b82675c50720 30
ryood 7:3f853801cb6d 31 #ifndef EXIOMCP23S17ROTARY_ENCODER_H
ryood 7:3f853801cb6d 32 #define EXIOMCP23S17ROTARY_ENCODER_H
ryood 5:b82675c50720 33
ryood 5:b82675c50720 34 #include "mbed.h"
ryood 5:b82675c50720 35 #include "ExioMcp23s17DigitalIn.h"
ryood 5:b82675c50720 36
ryood 5:b82675c50720 37 /**
ryood 5:b82675c50720 38 */
ryood 5:b82675c50720 39 class ExioMcp23s17RotaryEncoder
ryood 5:b82675c50720 40 {
ryood 5:b82675c50720 41 public:
ryood 5:b82675c50720 42 /**
ryood 5:b82675c50720 43 * Create rotary encoder.
ryood 6:1b3511093630 44 * @param device
ryood 6:1b3511093630 45 * @param port
ryood 5:b82675c50720 46 * @param pin1
ryood 5:b82675c50720 47 * @param pin2
ryood 5:b82675c50720 48 * @param min Minimum value.
ryood 5:b82675c50720 49 * @param max Maximum value.
ryood 5:b82675c50720 50 * @param val Default value.
ryood 5:b82675c50720 51 */
ryood 6:1b3511093630 52
ryood 5:b82675c50720 53 //RotaryEncoder(PinName pin1_name, PinName pin2_name, int min = 0, int max = 100, int val = 50);
ryood 6:1b3511093630 54 ExioMcp23s17RotaryEncoder(
ryood 6:1b3511093630 55 ExioMcp23s17& device, ExioPort port, int pin1_n, int pin2_n,
ryood 6:1b3511093630 56 int min = 0, int max = 100, int val = 50
ryood 6:1b3511093630 57 );
ryood 5:b82675c50720 58
ryood 5:b82675c50720 59 /**
ryood 5:b82675c50720 60 * Dispose.
ryood 5:b82675c50720 61 */
ryood 5:b82675c50720 62 ~ExioMcp23s17RotaryEncoder();
ryood 5:b82675c50720 63
ryood 5:b82675c50720 64 /**
ryood 5:b82675c50720 65 * Get the minimum value.
ryood 5:b82675c50720 66 *
ryood 5:b82675c50720 67 * @return The minimum value.
ryood 5:b82675c50720 68 */
ryood 5:b82675c50720 69 int getMin() const {
ryood 5:b82675c50720 70 return min;
ryood 5:b82675c50720 71 }
ryood 5:b82675c50720 72
ryood 5:b82675c50720 73 /**
ryood 5:b82675c50720 74 * Get the maximum value.
ryood 5:b82675c50720 75 *
ryood 5:b82675c50720 76 * @return The maximum value.
ryood 5:b82675c50720 77 */
ryood 5:b82675c50720 78 int getMax() const {
ryood 5:b82675c50720 79 return max;
ryood 5:b82675c50720 80 }
ryood 5:b82675c50720 81
ryood 5:b82675c50720 82 /**
ryood 5:b82675c50720 83 * Get the value.
ryood 5:b82675c50720 84 *
ryood 5:b82675c50720 85 * @return The value.
ryood 5:b82675c50720 86 */
ryood 5:b82675c50720 87 int getVal() const {
ryood 5:b82675c50720 88 return val;
ryood 5:b82675c50720 89 }
ryood 5:b82675c50720 90
ryood 5:b82675c50720 91 /**
ryood 5:b82675c50720 92 * Set the value.
ryood 5:b82675c50720 93 *
ryood 5:b82675c50720 94 * @param The value.
ryood 5:b82675c50720 95 */
ryood 5:b82675c50720 96 void setVal(int _val) {
ryood 5:b82675c50720 97 if (min <= _val && _val <= max) {
ryood 5:b82675c50720 98 val = _val;
ryood 5:b82675c50720 99 }
ryood 5:b82675c50720 100 }
ryood 5:b82675c50720 101
ryood 5:b82675c50720 102 /**
ryood 5:b82675c50720 103 * Set the ticker interval.
ryood 5:b82675c50720 104 *
ryood 5:b82675c50720 105 * @param The interval in microseconds.
ryood 5:b82675c50720 106 */
ryood 5:b82675c50720 107 void setInterval(timestamp_t t) {
ryood 5:b82675c50720 108 ticker.attach_us(this, &ExioMcp23s17RotaryEncoder::func_ticker, t);
ryood 5:b82675c50720 109 }
ryood 5:b82675c50720 110
ryood 5:b82675c50720 111 private:
ryood 6:1b3511093630 112 ExioMcp23s17DigitalIn* in1;
ryood 6:1b3511093630 113 ExioMcp23s17DigitalIn* in2;
ryood 5:b82675c50720 114 const int min;
ryood 5:b82675c50720 115 const int max;
ryood 5:b82675c50720 116 int val;
ryood 5:b82675c50720 117 Ticker ticker;
ryood 5:b82675c50720 118
ryood 5:b82675c50720 119 uint8_t code;
ryood 5:b82675c50720 120
ryood 5:b82675c50720 121 /**
ryood 5:b82675c50720 122 * Internal tick function.
ryood 5:b82675c50720 123 */
ryood 5:b82675c50720 124 void func_ticker();
ryood 5:b82675c50720 125 };
ryood 5:b82675c50720 126
ryood 5:b82675c50720 127 #endif