This short program illustrates how to use the DS130x_I2C library. My objective is to share the same RTC with Microchip 18F MCU.

Dependencies:   mbed DebugLibrary

Committer:
Yann
Date:
Fri Feb 11 10:17:20 2011 +0000
Revision:
1:995212d326ca
Parent:
0:f30e2135b0db
V0.0.0.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yann 0:f30e2135b0db 1
Yann 0:f30e2135b0db 2 /*
Yann 0:f30e2135b0db 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
Yann 0:f30e2135b0db 4
Yann 0:f30e2135b0db 5 Permission is hereby granted, free of charge, to any person obtaining a copy
Yann 0:f30e2135b0db 6 of this software and associated documentation files (the "Software"), to deal
Yann 0:f30e2135b0db 7 in the Software without restriction, including without limitation the rights
Yann 0:f30e2135b0db 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Yann 0:f30e2135b0db 9 copies of the Software, and to permit persons to whom the Software is
Yann 0:f30e2135b0db 10 furnished to do so, subject to the following conditions:
Yann 0:f30e2135b0db 11
Yann 0:f30e2135b0db 12 The above copyright notice and this permission notice shall be included in
Yann 0:f30e2135b0db 13 all copies or substantial portions of the Software.
Yann 0:f30e2135b0db 14
Yann 0:f30e2135b0db 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Yann 0:f30e2135b0db 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Yann 0:f30e2135b0db 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Yann 0:f30e2135b0db 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Yann 0:f30e2135b0db 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Yann 0:f30e2135b0db 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Yann 0:f30e2135b0db 21 THE SOFTWARE.
Yann 0:f30e2135b0db 22 */
Yann 0:f30e2135b0db 23
Yann 0:f30e2135b0db 24 /** \file
Yann 0:f30e2135b0db 25 UMTS Stick driver header file
Yann 0:f30e2135b0db 26 */
Yann 0:f30e2135b0db 27
Yann 0:f30e2135b0db 28 #ifndef UMTS_STICK_H
Yann 0:f30e2135b0db 29 #define UMTS_STICK_H
Yann 0:f30e2135b0db 30
Yann 0:f30e2135b0db 31 #include "mbed.h"
Yann 0:f30e2135b0db 32
Yann 0:f30e2135b0db 33 #include "drv/usb/UsbHostMgr.h"
Yann 0:f30e2135b0db 34 #include "drv/usb/UsbDevice.h"
Yann 0:f30e2135b0db 35 #include "drv/usb/UsbEndpoint.h"
Yann 0:f30e2135b0db 36
Yann 0:f30e2135b0db 37 #include "drv/serial/usb/UsbSerial.h"
Yann 0:f30e2135b0db 38
Yann 0:f30e2135b0db 39 #define UMTS_SWITCHING_COUNT 2
Yann 0:f30e2135b0db 40
Yann 0:f30e2135b0db 41 typedef unsigned char byte;
Yann 0:f30e2135b0db 42
Yann 0:f30e2135b0db 43 struct UMTSSwitchingInfo
Yann 0:f30e2135b0db 44 {
Yann 0:f30e2135b0db 45 uint16_t cdfsVid;
Yann 0:f30e2135b0db 46 uint16_t cdfsPid;
Yann 0:f30e2135b0db 47 uint16_t serialVid;
Yann 0:f30e2135b0db 48 uint16_t serialPidList[16];
Yann 0:f30e2135b0db 49 byte targetClass;
Yann 0:f30e2135b0db 50 bool huaweiPacket;
Yann 0:f30e2135b0db 51 byte cdfsPacket[31];
Yann 0:f30e2135b0db 52 };
Yann 0:f30e2135b0db 53
Yann 0:f30e2135b0db 54 extern const UMTSSwitchingInfo UMTSwitchingTable[UMTS_SWITCHING_COUNT];
Yann 0:f30e2135b0db 55
Yann 0:f30e2135b0db 56 ///UMTS Stick error codes
Yann 0:f30e2135b0db 57 enum UMTSStickErr
Yann 0:f30e2135b0db 58 {
Yann 0:f30e2135b0db 59 __UMTSERR_MIN = -0xFFFF,
Yann 0:f30e2135b0db 60 UMTSERR_NOTFOUND, ///<Stick was not found
Yann 0:f30e2135b0db 61 UMTSERR_NOTIMPLEMENTED, ///<This model is not implemented
Yann 0:f30e2135b0db 62 UMTSERR_USBERR, ///<USB Error
Yann 0:f30e2135b0db 63 UMTSERR_DISCONNECTED, ///<Stick disconnected
Yann 0:f30e2135b0db 64 UMTSERR_OK = 0 ///<Success
Yann 0:f30e2135b0db 65 };
Yann 0:f30e2135b0db 66
Yann 0:f30e2135b0db 67 class UMTSStick
Yann 0:f30e2135b0db 68 {
Yann 0:f30e2135b0db 69 public:
Yann 0:f30e2135b0db 70 UMTSStick();
Yann 0:f30e2135b0db 71 ~UMTSStick();
Yann 0:f30e2135b0db 72
Yann 0:f30e2135b0db 73 UMTSStickErr getSerial(UsbSerial** ppUsbSerial);
Yann 0:f30e2135b0db 74
Yann 0:f30e2135b0db 75 private:
Yann 0:f30e2135b0db 76 UMTSStickErr waitForDevice();
Yann 0:f30e2135b0db 77 UMTSStickErr checkDeviceState(const UMTSSwitchingInfo* pInfo, bool* pCdfs);
Yann 0:f30e2135b0db 78
Yann 0:f30e2135b0db 79 UMTSStickErr switchMode(const UMTSSwitchingInfo* pInfo);
Yann 0:f30e2135b0db 80 UMTSStickErr findSerial(UsbSerial** ppUsbSerial);
Yann 0:f30e2135b0db 81
Yann 0:f30e2135b0db 82
Yann 0:f30e2135b0db 83 UsbHostMgr m_host;
Yann 0:f30e2135b0db 84 UsbDevice* m_pDev;
Yann 0:f30e2135b0db 85 };
Yann 0:f30e2135b0db 86
Yann 0:f30e2135b0db 87 #endif