Add files via upload

This commit is contained in:
aster94 2017-12-06 21:52:00 +01:00 committed by GitHub
parent 595b128cac
commit dbfb68cf91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 43 deletions

View File

@ -25,7 +25,7 @@
*****************************************************************************/
/**
* @file Wire.cpp
* @file SoftWire.cpp
* @author Trystan Jones <crenn6977@gmail.com>
* @brief Wire library, uses the WireBase to create the primary interface
* while keeping low level interactions invisible to the user.
@ -54,7 +54,7 @@
* - always start with i2c_delay rather than end
*/
void TwoWire::set_scl(bool state) {
void SoftWire::set_scl(bool state) {
I2C_DELAY(this->i2c_delay);
gpio_write_bit(sclDevice,sclBit, state);
@ -65,30 +65,30 @@ void TwoWire::set_scl(bool state) {
}
}
void TwoWire::set_sda(bool state) {
void SoftWire::set_sda(bool state) {
I2C_DELAY(this->i2c_delay);
gpio_write_bit(sdaDevice,sdaBit, state);
//digitalWrite(this->sda_pin, state);
}
void TwoWire::i2c_start() {
void SoftWire::i2c_start() {
set_sda(LOW);
set_scl(LOW);
}
void TwoWire::i2c_stop() {
void SoftWire::i2c_stop() {
set_sda(LOW);
set_scl(HIGH);
set_sda(HIGH);
}
void TwoWire::i2c_repeated_start() {
void SoftWire::i2c_repeated_start() {
set_sda(HIGH);
set_scl(HIGH);
set_sda(LOW);
}
bool TwoWire::i2c_get_ack() {
bool SoftWire::i2c_get_ack() {
set_scl(LOW);
set_sda(HIGH);
set_scl(HIGH);
@ -98,19 +98,19 @@ bool TwoWire::i2c_get_ack() {
return ret;
}
void TwoWire::i2c_send_ack() {
void SoftWire::i2c_send_ack() {
set_sda(LOW);
set_scl(HIGH);
set_scl(LOW);
}
void TwoWire::i2c_send_nack() {
void SoftWire::i2c_send_nack() {
set_sda(HIGH);
set_scl(HIGH);
set_scl(LOW);
}
uint8 TwoWire::i2c_shift_in() {
uint8 SoftWire::i2c_shift_in() {
uint8 data = 0;
set_sda(HIGH);
@ -124,7 +124,7 @@ uint8 TwoWire::i2c_shift_in() {
return data;
}
void TwoWire::i2c_shift_out(uint8 val) {
void SoftWire::i2c_shift_out(uint8 val) {
int i;
for (i = 0; i < 8; i++) {
set_sda(!!(val & (1 << (7 - i)) ) );
@ -134,7 +134,7 @@ void TwoWire::i2c_shift_out(uint8 val) {
}
//process needs to be updated for repeated start.
uint8 TwoWire::process(uint8 stop) {
uint8 SoftWire::process(uint8 stop) {
itc_msg.xferred = 0;
uint8 sla_addr = (itc_msg.addr << 1);
@ -183,18 +183,18 @@ uint8 TwoWire::process(uint8 stop) {
}
// For compatibility with legacy code
uint8 TwoWire::process(){
uint8 SoftWire::process(){
return process(true);
}
// TODO: Add in Error Handling if pins is out of range for other Maples
// TODO: Make delays more capable
TwoWire::TwoWire(uint8 scl, uint8 sda, uint8 delay) : i2c_delay(delay) {
SoftWire::SoftWire(uint8 scl, uint8 sda, uint8 delay) : i2c_delay(delay) {
this->scl_pin=scl;
this->sda_pin=sda;
}
void TwoWire::begin(uint8 self_addr) {
void SoftWire::begin(uint8 self_addr) {
tx_buf_idx = 0;
tx_buf_overflow = false;
rx_buf_idx = 0;
@ -210,7 +210,7 @@ void TwoWire::begin(uint8 self_addr) {
set_sda(HIGH);
}
void TwoWire::end()
void SoftWire::end()
{
if (this->scl_pin)
{
@ -222,7 +222,7 @@ void TwoWire::end()
}
}
void TwoWire::setClock(uint32_t frequencyHz)
void SoftWire::setClock(uint32_t frequencyHz)
{
switch(frequencyHz)
{
@ -236,11 +236,11 @@ void TwoWire::setClock(uint32_t frequencyHz)
}
}
TwoWire::~TwoWire() {
SoftWire::~SoftWire() {
this->scl_pin=0;
this->sda_pin=0;
}
// Declare the instance that the users of the library can use
//TwoWire Wire(SCL, SDA, SOFT_STANDARD);
//TwoWire Wire(PB6, PB7, SOFT_FAST);
//SoftWire Wire(SCL, SDA, SOFT_STANDARD);
//SoftWire Wire(PB6, PB7, SOFT_FAST);

View File

@ -25,7 +25,7 @@
*****************************************************************************/
/**
* @file Wire.h
* @file SoftWire.h
* @author Trystan Jones <crenn6977@gmail.com>
* @brief Wire library, uses the WireBase to create the primary interface
* while keeping low level interactions invisible to the user.
@ -60,7 +60,7 @@
class TwoWire : public WireBase {
class SoftWire : public WireBase {
public:
uint8 i2c_delay;
uint8 scl_pin;
@ -136,7 +136,7 @@ class TwoWire : public WireBase {
* Accept pin numbers for SCL and SDA lines. Set the delay needed
* to create the timing for I2C's Standard Mode and Fast Mode.
*/
TwoWire(uint8 scl=SCL, uint8 sda=SDA, uint8 delay=SOFT_STANDARD);
SoftWire(uint8 scl=SCL, uint8 sda=SDA, uint8 delay=SOFT_STANDARD);
/*
* Sets pins SDA and SCL to OUPTUT_OPEN_DRAIN, joining I2C bus as
@ -155,9 +155,9 @@ class TwoWire : public WireBase {
/*
* If object is destroyed, set pin numbers to 0.
*/
~TwoWire();
~SoftWire();
};
//extern TwoWire Wire;
//extern SoftWire Wire;
#endif // _WIRE_H_
#endif // _SOFTWIRE_H_

View File

@ -25,7 +25,7 @@
*****************************************************************************/
/**
* @file HardWire.cpp
* @file TwoWire.cpp
* @author Trystan Jones <crenn6977@gmail.com>
* @brief Wire library, uses the hardware I2C available in the Maple to
* interact with I2C slave devices.
@ -38,7 +38,7 @@
#include "Wire.h"
uint8 HardWire::process(uint8 stop) {
uint8 TwoWire::process(uint8 stop) {
int8 res = i2c_master_xfer(sel_hard, &itc_msg, 1, 0);
if (res == I2C_ERROR_PROTOCOL) {
if (sel_hard->error_flags & I2C_SR1_AF) { /* NACK */
@ -55,12 +55,12 @@ uint8 HardWire::process(uint8 stop) {
return res;
}
uint8 HardWire::process(){
uint8 TwoWire::process(){
return process(true);
}
// TODO: Add in Error Handling if devsel is out of range for other Maples
HardWire::HardWire(uint8 dev_sel, uint8 flags) {
TwoWire::TwoWire(uint8 dev_sel, uint8 flags) {
if (dev_sel == 1) {
sel_hard = I2C1;
} else if (dev_sel == 2) {
@ -71,21 +71,21 @@ HardWire::HardWire(uint8 dev_sel, uint8 flags) {
dev_flags = flags;
}
HardWire::~HardWire() {
TwoWire::~TwoWire() {
i2c_disable(sel_hard);
sel_hard = 0;
}
void HardWire::begin(uint8 self_addr) {
void TwoWire::begin(uint8 self_addr) {
i2c_master_enable(sel_hard, dev_flags);
}
void HardWire::end() {
void TwoWire::end() {
i2c_disable(sel_hard);
sel_hard = 0;
}
void HardWire::setClock(uint32_t frequencyHz)
void TwoWire::setClock(uint32_t frequencyHz)
{
switch(frequencyHz)
{
@ -103,4 +103,4 @@ void HardWire::setClock(uint32_t frequencyHz)
}
}
HardWire Wire(1);
TwoWire Wire(1);

View File

@ -25,7 +25,7 @@
*****************************************************************************/
/**
* @file HardWire.h
* @file TwoWire.h
* @author Trystan Jones <crenn6977@gmail.com>
* @brief Wire library, uses the hardware I2C available in the Maple to
* interact with I2C slave devices.
@ -36,14 +36,14 @@
* users easy interaction with the I2C Hardware in a familiar method.
*/
#ifndef _HARDWIRE_H_
#define _HARDWIRE_H_
#ifndef _TWOWIRE_H_
#define _TWOWIRE_H_
#include "WireBase.h"
#include "wirish.h"
#include <libmaple/i2c.h>
class HardWire : public WireBase {
class TwoWire : public WireBase {
private:
i2c_dev* sel_hard;
uint8 dev_flags;
@ -59,7 +59,7 @@ public:
* Check if devsel is within range and enable selected I2C interface with
* passed flags
*/
HardWire(uint8, uint8 = 0);
TwoWire(uint8, uint8 = 0);
/*
* Shuts down (disables) the hardware I2C
@ -70,9 +70,9 @@ public:
/*
* Disables the I2C device and remove the device address.
*/
~HardWire();
~TwoWire();
void begin(uint8 = 0x00);
};
extern HardWire Wire;
#endif // _HARDWIRE_H_
extern TwoWire Wire;
#endif // _TWOWIRE_H_