Skip to content

Commit

Permalink
New MRTX-uno board was added
Browse files Browse the repository at this point in the history
This board is arduino uno compatible and with motor driver.

this board will be delivered in months in the robotic magazine in spain and Portugal firstable.

the idea is create and otto for this board too.
  • Loading branch information
logix5 committed Mar 12, 2022
1 parent 2976c7f commit 1591da7
Show file tree
Hide file tree
Showing 58 changed files with 2,862 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <Adafruit_BusIO_Register.h>

#if !defined(SPI_INTERFACES_COUNT) || \
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))

/*!
* @brief Create a register we access over an I2C Device (which defines the
* bus and address)
Expand Down Expand Up @@ -101,6 +104,19 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth);
}
if (_spidevice) {
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
// very special case!

// pass the special opcode address which we set as the high byte of the
// regaddr
addrbuffer[0] =
(uint8_t)(_address >> 8) & ~0x01; // set bottom bit low to write
// the 'actual' reg addr is the second byte then
addrbuffer[1] = (uint8_t)(_address & 0xFF);
// the address appears to be a byte longer
return _spidevice->write(buffer, len, addrbuffer, _addrwidth + 1);
}

if (_spiregtype == ADDRBIT8_HIGH_TOREAD) {
addrbuffer[0] &= ~0x80;
}
Expand Down Expand Up @@ -190,6 +206,19 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
}
if (_spidevice) {
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
// very special case!

// pass the special opcode address which we set as the high byte of the
// regaddr
addrbuffer[0] =
(uint8_t)(_address >> 8) | 0x01; // set bottom bit high to read
// the 'actual' reg addr is the second byte then
addrbuffer[1] = (uint8_t)(_address & 0xFF);
// the address appears to be a byte longer
return _spidevice->write_then_read(addrbuffer, _addrwidth + 1, buffer,
len);
}
if (_spiregtype == ADDRBIT8_HIGH_TOREAD) {
addrbuffer[0] |= 0x80;
}
Expand Down Expand Up @@ -310,3 +339,27 @@ bool Adafruit_BusIO_RegisterBits::write(uint32_t data) {
* @returns The data width used when initializing the register
*/
uint8_t Adafruit_BusIO_Register::width(void) { return _width; }

/*!
* @brief Set the default width of data
* @param width the default width of data read from register
*/
void Adafruit_BusIO_Register::setWidth(uint8_t width) { _width = width; }

/*!
* @brief Set register address
* @param address the address from register
*/
void Adafruit_BusIO_Register::setAddress(uint16_t address) {
_address = address;
}

/*!
* @brief Set the width of register address
* @param address_width the width for register address
*/
void Adafruit_BusIO_Register::setAddressWidth(uint16_t address_width) {
_addrwidth = address_width;
}

#endif // SPI exists
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
#include <Adafruit_I2CDevice.h>
#include <Adafruit_SPIDevice.h>
#include <Arduino.h>

#ifndef Adafruit_BusIO_Register_h
#define Adafruit_BusIO_Register_h

#include <Arduino.h>

#if !defined(SPI_INTERFACES_COUNT) || \
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))

#include <Adafruit_I2CDevice.h>
#include <Adafruit_SPIDevice.h>

typedef enum _Adafruit_BusIO_SPIRegType {
ADDRBIT8_HIGH_TOREAD = 0,
/*!<
* ADDRBIT8_HIGH_TOREAD
* When reading a register you must actually send the value 0x80 + register
* address to the device. e.g. To read the register 0x0B the register value
* 0x8B is sent and to write 0x0B is sent.
*/
AD8_HIGH_TOREAD_AD7_HIGH_TOINC = 1,

/*!<
* ADDRBIT8_HIGH_TOWRITE
* When writing to a register you must actually send the value 0x80 +
* the register address to the device. e.g. To write to the register 0x19 the
* register value 0x99 is sent and to read 0x19 is sent.
*/
ADDRBIT8_HIGH_TOWRITE = 2,

/*!<
* ADDRESSED_OPCODE_LOWBIT_TO_WRITE
* Used by the MCP23S series, we send 0x40 |'rd with the opcode
* Then set the lowest bit to write
*/
ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE = 3,

} Adafruit_BusIO_SPIRegType;

/*!
Expand All @@ -20,6 +45,7 @@ class Adafruit_BusIO_Register {
Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, uint16_t reg_addr,
uint8_t width = 1, uint8_t byteorder = LSBFIRST,
uint8_t address_width = 1);

Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr,
Adafruit_BusIO_SPIRegType type, uint8_t width = 1,
uint8_t byteorder = LSBFIRST,
Expand All @@ -41,6 +67,10 @@ class Adafruit_BusIO_Register {

uint8_t width(void);

void setWidth(uint8_t width);
void setAddress(uint16_t address);
void setAddressWidth(uint16_t address_width);

void print(Stream *s = &Serial);
void println(Stream *s = &Serial);

Expand All @@ -50,7 +80,7 @@ class Adafruit_BusIO_Register {
Adafruit_BusIO_SPIRegType _spiregtype;
uint16_t _address;
uint8_t _width, _addrwidth, _byteorder;
uint8_t _buffer[4]; // we wont support anything larger than uint32 for
uint8_t _buffer[4]; // we won't support anything larger than uint32 for
// non-buffered read
uint32_t _cached = 0;
};
Expand All @@ -71,4 +101,5 @@ class Adafruit_BusIO_RegisterBits {
uint8_t _bits, _shift;
};

#endif // SPI exists
#endif // BusIO_Register_h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <Adafruit_I2CDevice.h>
#include <Arduino.h>
#include "Adafruit_I2CDevice.h"

//#define DEBUG_SERIAL Serial

Expand Down Expand Up @@ -36,6 +35,23 @@ bool Adafruit_I2CDevice::begin(bool addr_detect) {
return true;
}

/*!
* @brief De-initialize device, turn off the Wire interface
*/
void Adafruit_I2CDevice::end(void) {
// Not all port implement Wire::end(), such as
// - ESP8266
// - AVR core without WIRE_HAS_END
// - ESP32: end() is implemented since 2.0.1 which is latest at the moment.
// Temporarily disable for now to give time for user to update.
#if !(defined(ESP8266) || \
(defined(ARDUINO_ARCH_AVR) && !defined(WIRE_HAS_END)) || \
defined(ARDUINO_ARCH_ESP32))
_wire->end();
_begun = false;
#endif
}

/*!
* @brief Scans I2C for the address - note will give a false-positive
* if there's no pullups on I2C
Expand All @@ -50,8 +66,14 @@ bool Adafruit_I2CDevice::detected(void) {
// A basic scanner, see if it ACK's
_wire->beginTransmission(_addr);
if (_wire->endTransmission() == 0) {
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("Detected"));
#endif
return true;
}
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("Not detected"));
#endif
return false;
}

Expand Down Expand Up @@ -121,21 +143,21 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
DEBUG_SERIAL.println();
}
}
DEBUG_SERIAL.println();
#endif

#ifdef DEBUG_SERIAL
// DEBUG_SERIAL.print("Stop: "); DEBUG_SERIAL.println(stop);
if (stop) {
DEBUG_SERIAL.print("\tSTOP");
}
#endif

if (_wire->endTransmission(stop) == 0) {
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println();
// DEBUG_SERIAL.println("Sent!");
#endif
return true;
} else {
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println("Failed to send!");
DEBUG_SERIAL.println("\tFailed to send!");
#endif
return false;
}
Expand All @@ -150,17 +172,25 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
* @return True if read was successful, otherwise false.
*/
bool Adafruit_I2CDevice::read(uint8_t *buffer, size_t len, bool stop) {
if (len > maxBufferSize()) {
// currently not guaranteed to work if more than 32 bytes!
// we will need to find out if some platforms have larger
// I2C buffer sizes :/
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("\tI2CDevice could not read such a large buffer"));
#endif
return false;
size_t pos = 0;
while (pos < len) {
size_t read_len =
((len - pos) > maxBufferSize()) ? maxBufferSize() : (len - pos);
bool read_stop = (pos < (len - read_len)) ? false : stop;
if (!_read(buffer + pos, read_len, read_stop))
return false;
pos += read_len;
}
return true;
}

bool Adafruit_I2CDevice::_read(uint8_t *buffer, size_t len, bool stop) {
#if defined(TinyWireM_h)
size_t recv = _wire->requestFrom((uint8_t)_addr, (uint8_t)len);
#else
size_t recv = _wire->requestFrom((uint8_t)_addr, (uint8_t)len, (uint8_t)stop);
#endif

if (recv != len) {
// Not enough data available to fulfill our obligation!
#ifdef DEBUG_SERIAL
Expand Down Expand Up @@ -227,10 +257,11 @@ uint8_t Adafruit_I2CDevice::address(void) { return _addr; }
* Not necessarily that the speed was achieved!
*/
bool Adafruit_I2CDevice::setSpeed(uint32_t desiredclk) {
#if (ARDUINO >= 157) && !defined(ARDUINO_STM32_FEATHER)
#if (ARDUINO >= 157) && !defined(ARDUINO_STM32_FEATHER) && !defined(TinyWireM_h)
_wire->setClock(desiredclk);
return true;
#else
(void)desiredclk;
return false;
#endif
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include <Wire.h>

#ifndef Adafruit_I2CDevice_h
#define Adafruit_I2CDevice_h

#include <Arduino.h>
#include <Wire.h>

///< The class which defines how we will talk to this device over I2C
class Adafruit_I2CDevice {
public:
Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
uint8_t address(void);
bool begin(bool addr_detect = true);
void end(void);
bool detected(void);

bool read(uint8_t *buffer, size_t len, bool stop = true);
Expand All @@ -28,6 +30,7 @@ class Adafruit_I2CDevice {
TwoWire *_wire;
bool _begun;
size_t _maxBufferSize;
bool _read(uint8_t *buffer, size_t len, bool stop);
};

#endif // Adafruit_I2CDevice_h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "Adafruit_BusIO_Register.h"
#ifndef _ADAFRUIT_I2C_REGISTER_H_
#define _ADAFRUIT_I2C_REGISTER_H_

#include <Adafruit_BusIO_Register.h>
#include <Arduino.h>

typedef Adafruit_BusIO_Register Adafruit_I2CRegister;
typedef Adafruit_BusIO_RegisterBits Adafruit_I2CRegisterBits;

Expand Down
Loading

0 comments on commit 1591da7

Please sign in to comment.