- Timestamp:
- Mar 28, 2016, 2:09:46 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/libraries/Wire/Wire.h
r136 r175 1 1 /* 2 * TwoWire.h - TWI/I2C library for Arduino Due 3 * Copyright (c) 2011 Cristian Maglie <c.maglie@bug.st>. 4 * All rights reserved. 2 * TWI/I2C library for Arduino Zero 3 * Copyright (c) 2015 Arduino LLC. All rights reserved. 5 4 * 6 5 * This library is free software; you can redistribute it and/or … … 22 21 #define TwoWire_h 23 22 24 //#include <include/twi.h>25 26 23 #include "Stream.h" 27 24 #include "variant.h" … … 32 29 #define BUFFER_LENGTH 32 33 30 31 // WIRE_HAS_END means Wire has end() 32 #define WIRE_HAS_END 1 34 33 35 34 class TwoWire : public Stream 36 35 { 37 public: 38 TwoWire(SERCOM *s); 39 void begin(); 40 void begin(uint8_t); 36 public: 37 TwoWire(SERCOM *s, uint8_t pinSDA, uint8_t pinSCL); 38 void begin(); 39 void begin(uint8_t); 40 void end(); 41 void setClock(uint32_t); 41 42 42 43 44 43 void beginTransmission(uint8_t); 44 uint8_t endTransmission(bool stopBit); 45 uint8_t endTransmission(void); 45 46 46 47 47 uint8_t requestFrom(uint8_t address, size_t quantity, bool stopBit); 48 uint8_t requestFrom(uint8_t address, size_t quantity); 48 49 49 50 50 size_t write(uint8_t data); 51 size_t write(const uint8_t * data, size_t quantity); 51 52 52 53 54 55 56 57 53 virtual int available(void); 54 virtual int read(void); 55 virtual int peek(void); 56 virtual void flush(void); 57 void onReceive(void(*)(int)); 58 void onRequest(void(*)(void)); 58 59 59 60 using Print::write; 60 61 61 62 void onService(void); 62 63 63 private: 64 SERCOM * sercom; 65 bool transmissionBegun; 64 private: 65 SERCOM * sercom; 66 uint8_t _uc_pinSDA; 67 uint8_t _uc_pinSCL; 66 68 67 // RX Buffer 68 RingBuffer rxBuffer; 69 bool transmissionBegun; 69 70 70 //TX buffer 71 RingBuffer txBuffer; 72 uint8_t txAddress; 71 // RX Buffer 72 RingBuffer rxBuffer; 73 74 //TX buffer 75 RingBuffer txBuffer; 76 uint8_t txAddress; 73 77 74 78 75 76 77 78 79 // Service buffer 80 //uint8_t srvBuffer[BUFFER_LENGTH]; 81 //uint8_t srvBufferIndex; 82 //uint8_t srvBufferLength; 79 83 80 81 82 84 // Callback user functions 85 void (*onRequestCallback)(void); 86 void (*onReceiveCallback)(int); 83 87 84 85 88 // TWI state 89 //enum TwoWireStatus 86 90 //{ 87 //UNINITIALIZED,88 //MASTER_IDLE,89 //MASTER_SEND,90 //MASTER_RECV,91 //SLAVE_IDLE,92 //SLAVE_RECV,93 //SLAVE_SEND94 95 91 // UNINITIALIZED, 92 // MASTER_IDLE, 93 // MASTER_SEND, 94 // MASTER_RECV, 95 // SLAVE_IDLE, 96 // SLAVE_RECV, 97 // SLAVE_SEND 98 //}; 99 //TwoWireStatus status; 96 100 97 98 101 // TWI clock frequency 102 static const uint32_t TWI_CLOCK = 100000; 99 103 100 101 102 104 // Timeouts 105 //static const uint32_t RECV_TIMEOUT = 100000; 106 //static const uint32_t XMIT_TIMEOUT = 100000; 103 107 }; 104 108 105 extern TwoWire Wire; 109 #if WIRE_INTERFACES_COUNT > 0 110 extern TwoWire Wire; 111 #endif 112 #if WIRE_INTERFACES_COUNT > 1 113 extern TwoWire Wire1; 114 #endif 115 #if WIRE_INTERFACES_COUNT > 2 116 extern TwoWire Wire2; 117 #endif 118 #if WIRE_INTERFACES_COUNT > 3 119 extern TwoWire Wire3; 120 #endif 121 #if WIRE_INTERFACES_COUNT > 4 122 extern TwoWire Wire4; 123 #endif 124 #if WIRE_INTERFACES_COUNT > 5 125 extern TwoWire Wire5; 126 #endif 106 127 107 128 #endif
Note:
See TracChangeset
for help on using the changeset viewer.