pefect / Mbed 2 deprecated WizFi310_TCP_Echo_Server_Example

Dependencies:   NetworkSocketAPI WizFi310Interface mbed

Fork of WizFi310_TCP_Echo_Server_Example by WIZnet

Committer:
maru536
Date:
Mon Oct 02 20:48:08 2017 +0000
Revision:
2:8d119e9b8f5a
AP mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maru536 2:8d119e9b8f5a 1 /* mbed Shift Register Library, such as for NXP 74HC595
maru536 2:8d119e9b8f5a 2 * Copyright (c) 2012, YoongHM
maru536 2:8d119e9b8f5a 3 *
maru536 2:8d119e9b8f5a 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
maru536 2:8d119e9b8f5a 5 * of this software and associated documentation files (the "Software"), to deal
maru536 2:8d119e9b8f5a 6 * in the Software without restriction, including without limitation the rights
maru536 2:8d119e9b8f5a 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
maru536 2:8d119e9b8f5a 8 * copies of the Software, and to permit persons to whom the Software is
maru536 2:8d119e9b8f5a 9 * furnished to do so, subject to the following conditions:
maru536 2:8d119e9b8f5a 10 *
maru536 2:8d119e9b8f5a 11 * The above copyright notice and this permission notice shall be included in
maru536 2:8d119e9b8f5a 12 * all copies or substantial portions of the Software.
maru536 2:8d119e9b8f5a 13 *
maru536 2:8d119e9b8f5a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
maru536 2:8d119e9b8f5a 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
maru536 2:8d119e9b8f5a 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
maru536 2:8d119e9b8f5a 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
maru536 2:8d119e9b8f5a 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
maru536 2:8d119e9b8f5a 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
maru536 2:8d119e9b8f5a 20 * THE SOFTWARE.
maru536 2:8d119e9b8f5a 21 */
maru536 2:8d119e9b8f5a 22
maru536 2:8d119e9b8f5a 23 #ifndef _SHIFTREGISTERCONTROLCLASS_H
maru536 2:8d119e9b8f5a 24 #define _SHIFTREGISTERCONTROLCLASS_H
maru536 2:8d119e9b8f5a 25
maru536 2:8d119e9b8f5a 26 #include "mbed.h"
maru536 2:8d119e9b8f5a 27
maru536 2:8d119e9b8f5a 28 /** A interface to drive shifter register as such 74HCT595
maru536 2:8d119e9b8f5a 29 *
maru536 2:8d119e9b8f5a 30 * @code
maru536 2:8d119e9b8f5a 31 * #include "mbed.h"
maru536 2:8d119e9b8f5a 32 * #include "ShiftReg.h"
maru536 2:8d119e9b8f5a 33 *
maru536 2:8d119e9b8f5a 34 * ShiftReg HC595(p21, p22, p23);
maru536 2:8d119e9b8f5a 35 *
maru536 2:8d119e9b8f5a 36 * int main() {
maru536 2:8d119e9b8f5a 37 * // clear shift and store registers initially
maru536 2:8d119e9b8f5a 38 * HC595.ShiftByte(0x00, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 39 *
maru536 2:8d119e9b8f5a 40 * while(1) {
maru536 2:8d119e9b8f5a 41 * // Demostrate to shift in bit by bit
maru536 2:8d119e9b8f5a 42 * HC595.ShiftBit(1); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 43 * for (int i = 0; i < 8; i++) {
maru536 2:8d119e9b8f5a 44 * HC595.ShiftBit(0); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 45 * }
maru536 2:8d119e9b8f5a 46
maru536 2:8d119e9b8f5a 47 * // Demostrate to shift in byte-by-byte
maru536 2:8d119e9b8f5a 48 * // HC595.ShiftByte(0x80, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 49 * HC595.ShiftByte(0x40, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 50 * HC595.ShiftByte(0x20, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 51 * HC595.ShiftByte(0x10, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 52 * HC595.ShiftByte(0x08, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 53 * HC595.ShiftByte(0x04, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 54 * HC595.ShiftByte(0x02, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 55 * HC595.ShiftByte(0x01, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 56 * HC595.ShiftByte(0x00, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2);
maru536 2:8d119e9b8f5a 57 * }
maru536 2:8d119e9b8f5a 58 * }
maru536 2:8d119e9b8f5a 59 * @endcode
maru536 2:8d119e9b8f5a 60 */
maru536 2:8d119e9b8f5a 61
maru536 2:8d119e9b8f5a 62 class ShiftRegisterControlClass
maru536 2:8d119e9b8f5a 63 {
maru536 2:8d119e9b8f5a 64 public:
maru536 2:8d119e9b8f5a 65 /** Bit order out format */
maru536 2:8d119e9b8f5a 66 enum BitOrd {
maru536 2:8d119e9b8f5a 67 MSBFirst = 0x80, /**< Most significant bit first */
maru536 2:8d119e9b8f5a 68 LSBFirst = 0x01 /**< Least significant bit first */
maru536 2:8d119e9b8f5a 69
maru536 2:8d119e9b8f5a 70 };
maru536 2:8d119e9b8f5a 71
maru536 2:8d119e9b8f5a 72 enum LedByteSet {
maru536 2:8d119e9b8f5a 73 //MSB FIRST
maru536 2:8d119e9b8f5a 74 //Q7(error)|Q6(debugB)|Q5(debugA)|Q4(ledC)|Q3(ledB)|Q2(ledA)|Q1(wifi)|Q0(power)|
maru536 2:8d119e9b8f5a 75 //
maru536 2:8d119e9b8f5a 76 kPowerLedByte = 0b00000001,
maru536 2:8d119e9b8f5a 77 kWifiLedByte = 0b00000010,
maru536 2:8d119e9b8f5a 78 kIndiAByte = 0b00000100,
maru536 2:8d119e9b8f5a 79 kIndiBByte = 0b00001000,
maru536 2:8d119e9b8f5a 80 kIndiCByte = 0b00010000,
maru536 2:8d119e9b8f5a 81 kDebugLedAByte = 0b00100000,
maru536 2:8d119e9b8f5a 82 kDebugLedBByte = 0b01000000,
maru536 2:8d119e9b8f5a 83 kErrorLedByte = 0b10000010,
maru536 2:8d119e9b8f5a 84 kAllOnLedByte = 0xFF,
maru536 2:8d119e9b8f5a 85 kAllOffLedByte = 0x00
maru536 2:8d119e9b8f5a 86 };
maru536 2:8d119e9b8f5a 87 /** Create a ShiftReg interface to shift register
maru536 2:8d119e9b8f5a 88 *
maru536 2:8d119e9b8f5a 89 * @param data Pin to serial input to shift register
maru536 2:8d119e9b8f5a 90 * @param store Pin to store register
maru536 2:8d119e9b8f5a 91 * @param clock Pin to shift into register
maru536 2:8d119e9b8f5a 92 */
maru536 2:8d119e9b8f5a 93 ShiftRegisterControlClass(PinName data,PinName store,PinName clock);
maru536 2:8d119e9b8f5a 94
maru536 2:8d119e9b8f5a 95 /** Shift out 8-bit data via the serial pin
maru536 2:8d119e9b8f5a 96 *
maru536 2:8d119e9b8f5a 97 * @param data Data to be shifted out via the serial pin
maru536 2:8d119e9b8f5a 98 * @param order Bit order to shift out data. Default is MSBFirst
maru536 2:8d119e9b8f5a 99 */
maru536 2:8d119e9b8f5a 100 void ShiftByte(int8_t data,BitOrd ord = MSBFirst);
maru536 2:8d119e9b8f5a 101
maru536 2:8d119e9b8f5a 102 /** Shift out 1-bit data via the serial pin
maru536 2:8d119e9b8f5a 103 *
maru536 2:8d119e9b8f5a 104 * @param data Data to be shifted out via the serial pin
maru536 2:8d119e9b8f5a 105 */
maru536 2:8d119e9b8f5a 106 void ShiftBit(int8_t data = 0);
maru536 2:8d119e9b8f5a 107
maru536 2:8d119e9b8f5a 108 /** Latch data out
maru536 2:8d119e9b8f5a 109 */
maru536 2:8d119e9b8f5a 110 void Latch();
maru536 2:8d119e9b8f5a 111
maru536 2:8d119e9b8f5a 112 //adding custom method
maru536 2:8d119e9b8f5a 113 void TurnOnLed(int8_t data);
maru536 2:8d119e9b8f5a 114 void TurnOffLed(int8_t data);
maru536 2:8d119e9b8f5a 115 void LightAllLed();
maru536 2:8d119e9b8f5a 116 void BlackOutLed();
maru536 2:8d119e9b8f5a 117 void BlinkLed();
maru536 2:8d119e9b8f5a 118 int8_t get_my_mask_byte();
maru536 2:8d119e9b8f5a 119
maru536 2:8d119e9b8f5a 120 private:
maru536 2:8d119e9b8f5a 121 DigitalOut _ds; // Serial in
maru536 2:8d119e9b8f5a 122 DigitalOut _st; // store register or latch
maru536 2:8d119e9b8f5a 123 DigitalOut _sh; // shift register
maru536 2:8d119e9b8f5a 124 BitOrd _ord; // Bit order to shift out data
maru536 2:8d119e9b8f5a 125 uint8_t mask_byte_;//adding custom variables
maru536 2:8d119e9b8f5a 126 };
maru536 2:8d119e9b8f5a 127
maru536 2:8d119e9b8f5a 128 #endif // _SHIFTREG_H