add trinket/attiny8 support

This commit is contained in:
ladyada 2021-06-30 16:46:43 -04:00
parent 1bd76737a2
commit 05398d9395
6 changed files with 33 additions and 4 deletions

View File

@ -20,7 +20,7 @@ jobs:
run: bash ci/actions_install.sh run: bash ci/actions_install.sh
- name: test platforms - name: test platforms
run: python3 ci/build_platform.py main_platforms run: python3 ci/build_platform.py main_platforms trinket5v
- name: clang - name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .

View File

@ -1,5 +1,7 @@
#include <Adafruit_BusIO_Register.h> #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 * @brief Create a register we access over an I2C Device (which defines the
* bus and address) * bus and address)
@ -358,3 +360,6 @@ void Adafruit_BusIO_Register::setAddress(uint16_t address) {
void Adafruit_BusIO_Register::setAddressWidth(uint16_t address_width) { void Adafruit_BusIO_Register::setAddressWidth(uint16_t address_width) {
_addrwidth = address_width; _addrwidth = address_width;
} }
#endif // SPI exists

View File

@ -2,6 +2,8 @@
#include <Adafruit_SPIDevice.h> #include <Adafruit_SPIDevice.h>
#include <Arduino.h> #include <Arduino.h>
#if !defined(SPI_INTERFACES_COUNT) || (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
#ifndef Adafruit_BusIO_Register_h #ifndef Adafruit_BusIO_Register_h
#define Adafruit_BusIO_Register_h #define Adafruit_BusIO_Register_h
@ -98,3 +100,5 @@ private:
}; };
#endif // BusIO_Register_h #endif // BusIO_Register_h
#endif // SPI exists

View File

@ -50,8 +50,14 @@ bool Adafruit_I2CDevice::detected(void) {
// A basic scanner, see if it ACK's // A basic scanner, see if it ACK's
_wire->beginTransmission(_addr); _wire->beginTransmission(_addr);
if (_wire->endTransmission() == 0) { if (_wire->endTransmission() == 0) {
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("Detected"));
#endif
return true; return true;
} }
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("Not detected"));
#endif
return false; return false;
} }
@ -125,7 +131,8 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
#endif #endif
#ifdef DEBUG_SERIAL #ifdef DEBUG_SERIAL
// DEBUG_SERIAL.print("Stop: "); DEBUG_SERIAL.println(stop); DEBUG_SERIAL.print("Stop: ");
DEBUG_SERIAL.println(stop);
#endif #endif
if (_wire->endTransmission(stop) == 0) { if (_wire->endTransmission(stop) == 0) {
@ -160,7 +167,12 @@ bool Adafruit_I2CDevice::read(uint8_t *buffer, size_t len, bool stop) {
return false; return false;
} }
#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); size_t recv = _wire->requestFrom((uint8_t)_addr, (uint8_t)len, (uint8_t)stop);
#endif
if (recv != len) { if (recv != len) {
// Not enough data available to fulfill our obligation! // Not enough data available to fulfill our obligation!
#ifdef DEBUG_SERIAL #ifdef DEBUG_SERIAL
@ -227,10 +239,11 @@ uint8_t Adafruit_I2CDevice::address(void) { return _addr; }
* Not necessarily that the speed was achieved! * Not necessarily that the speed was achieved!
*/ */
bool Adafruit_I2CDevice::setSpeed(uint32_t desiredclk) { 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); _wire->setClock(desiredclk);
return true; return true;
#else #else
(void)desiredclk;
return false; return false;
#endif #endif
} }

View File

@ -1,5 +1,7 @@
#include <Adafruit_SPIDevice.h>
#include <Arduino.h> #include <Arduino.h>
#include <Adafruit_SPIDevice.h>
#if !defined(SPI_INTERFACES_COUNT) || (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
//#define DEBUG_SERIAL Serial //#define DEBUG_SERIAL Serial
@ -437,3 +439,5 @@ bool Adafruit_SPIDevice::write_then_read(uint8_t *write_buffer,
return true; return true;
} }
#endif // SPI exists

View File

@ -1,3 +1,5 @@
#if !defined(SPI_INTERFACES_COUNT) || (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
#include <SPI.h> #include <SPI.h>
#ifndef Adafruit_SPIDevice_h #ifndef Adafruit_SPIDevice_h
@ -97,3 +99,4 @@ private:
}; };
#endif // Adafruit_SPIDevice_h #endif // Adafruit_SPIDevice_h
#endif // has SPI defined