Merge branch 'aster94-master'
This commit is contained in:
commit
c5133eba8f
|
@ -22,10 +22,10 @@ All text above, and the splash screen below must be included in any redistributi
|
|||
//#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
//#include <Wire.h>
|
||||
|
||||
#include <Wire.h>
|
||||
//HardWire HWIRE(1,I2C_FAST_MODE); // I2c1
|
||||
//HardWire HWIRE(2,I2C_FAST_MODE); // I2c2
|
||||
//TwoWire WIRE(1,I2C_FAST_MODE); // I2c1
|
||||
//TwoWire WIRE(2,I2C_FAST_MODE); // I2c2
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_SSD1306_STM32.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
STM32 adaption by Matthias Diro, 25.03.2015
|
||||
Things to know:
|
||||
This adaption uses hardware I2C (hardwire.h), Port: I2c2. SDA=0, SCL=1 on maple mini
|
||||
This adaption uses hardware I2C (now Wire.h), Port: I2c2. SDA=0, SCL=1 on maple mini
|
||||
To change it to Port I2C1:
|
||||
//HardWire HWIRE(1,I2C_FAST_MODE); // I2c1
|
||||
HardWire HWIRE(2,I2C_FAST_MODE); // I2c2
|
||||
//TwoWire WIRE(1,I2C_FAST_MODE); // I2c1
|
||||
TwoWire WIRE(2,I2C_FAST_MODE); // I2c2
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
STM32 adaption by Matthias Diro, tested with maple mini and heltec OLED 12864 I2c; adress: 0x3C (SPI should work, but I didn't own one)
|
||||
Things to know:
|
||||
This adaption uses hardware I2C (hardwire.h), Port: I2c2. SDA=0, SCL=1 on maple mini
|
||||
This adaption uses hardware I2C (now Wire.h), Port: I2c2. SDA=0, SCL=1 on maple mini
|
||||
further details: STM32_README.txt
|
||||
*/
|
||||
/*********************************************************************
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
*/
|
||||
#elif defined (__STM32F1__)
|
||||
#include "Arduino.h"
|
||||
//#include <HardWire.h>
|
||||
//#include <Wire.h>
|
||||
#include "hardware/arm/HW_STM32_defines.h"
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "Wire.h"
|
||||
#define WIRE_WRITE HWIRE.write
|
||||
|
||||
HardWire HWIRE(2,I2C_FAST_MODE); // stupid compiler
|
||||
TwoWire WIRE(2,I2C_FAST_MODE); // stupid compiler
|
||||
|
||||
void OLED::_convert_float(char *buf, double num, int width, byte prec)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
@ -40,7 +40,7 @@
|
|||
#ifndef _SOFTWIRE_H_
|
||||
#define _SOFTWIRE_H_
|
||||
|
||||
#include "WireBase.h"
|
||||
#include "utility/WireBase.h"
|
||||
#include "wirish.h"
|
||||
|
||||
/*
|
||||
|
@ -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_
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file HardWire.h
|
||||
* @file Wire.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 "utility/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_
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
// --------------------------------------
|
||||
// i2c_scanner
|
||||
//
|
||||
// Version 1
|
||||
// This program (or code that looks like it)
|
||||
// can be found in many places.
|
||||
// For example on the Arduino.cc forum.
|
||||
// The original author is not know.
|
||||
// Version 2, Juni 2012, Using Arduino 1.0.1
|
||||
// Adapted to be as simple as possible by Arduino.cc user Krodal
|
||||
// Version 3, Feb 26 2013
|
||||
// V3 by louarnold
|
||||
// Version 4, March 3, 2013, Using Arduino 1.0.3
|
||||
// by Arduino.cc user Krodal.
|
||||
// Changes by louarnold removed.
|
||||
// Scanning addresses changed from 0...127 to 1...119,
|
||||
// according to the i2c scanner by Nick Gammon
|
||||
// http://www.gammon.com.au/forum/?id=10896
|
||||
// Version 5, March 28, 2013
|
||||
// As version 4, but address scans now to 127.
|
||||
// A sensor seems to use address 120.
|
||||
// Version 6, August 1, 2015
|
||||
// Modified to support HardWire for STM32duino
|
||||
//
|
||||
// This sketch tests the standard 7-bit addresses
|
||||
// Devices with higher bit address might not be seen properly.
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
HardWire HWire(1, I2C_FAST_MODE); // I2c1
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
HWire.begin();
|
||||
Serial.println("\nI2C Scanner");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
|
||||
Serial.println("Scanning...");
|
||||
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++) {
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
|
||||
HWire.beginTransmission(address);
|
||||
error = HWire.endTransmission();
|
||||
|
||||
if (error == 0) {
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (address < 16)
|
||||
Serial.print("0");
|
||||
Serial.println(address, HEX);
|
||||
|
||||
nDevices++;
|
||||
}
|
||||
else if (error == 4) {
|
||||
Serial.print("Unknown error at address 0x");
|
||||
if (address < 16)
|
||||
Serial.print("0");
|
||||
Serial.println(address, HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found");
|
||||
else
|
||||
Serial.println("done");
|
||||
|
||||
delay(5000); // wait 5 seconds for next scan
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <SoftWire.h>
|
||||
|
||||
TwoWire SWire(PB6, PB7, SOFT_FAST);
|
||||
SoftWire SWire(PB6, PB7, SOFT_FAST);
|
||||
|
||||
|
||||
void setup() {
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
|
||||
#include <Wire.h>
|
||||
|
||||
//use IIC2
|
||||
//TwoWire WIRE2 (2,I2C_FAST_MODE);
|
||||
//#define Wire WIRE2
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
|
@ -71,4 +75,4 @@ void loop() {
|
|||
Serial.println("done");
|
||||
|
||||
delay(5000); // wait 5 seconds for next scan
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
TwoWire KEYWORD1
|
||||
SoftWire KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
SOFT_STANDARD LITERAL1
|
||||
SOFT_FAST LITERAL1
|
||||
I2C_FAST_MODE LITERAL1
|
|
@ -1,3 +1,7 @@
|
|||
#this makefile may not work since HardWire has been changed to the default Wire (TwoWire)
|
||||
#anyway this file should be useless
|
||||
|
||||
|
||||
# Standard things
|
||||
sp := $(sp).x
|
||||
dirstack_$(sp) := $(d)
|
||||
|
|
Loading…
Reference in New Issue