Compare commits
16 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d029f1dfde | ||
|
|
832893d52d | ||
|
|
da4643b05b | ||
|
|
fb054412c3 | ||
|
|
8cf568b75d | ||
|
|
7632137956 | ||
|
|
88f67aff99 | ||
|
|
9153ca98c4 | ||
|
|
41c01b6aae | ||
|
|
7709a19837 | ||
|
|
b5944766cb | ||
|
|
e447e7bec6 | ||
|
|
51d890da25 | ||
|
|
4fb204ef8d | ||
|
|
c0e0b805a3 | ||
|
|
baac84d538 |
15 changed files with 194 additions and 109 deletions
6
.github/workflows/githubci.yml
vendored
6
.github/workflows/githubci.yml
vendored
|
|
@ -7,11 +7,11 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-python@v1
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.x'
|
python-version: '3.x'
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: adafruit/ci-arduino
|
repository: adafruit/ci-arduino
|
||||||
path: ci
|
path: ci
|
||||||
|
|
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2017 Sandeep Mistry
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
0
examples/feather_m4can_neotran/.feather_m4_can.test.only
Normal file
0
examples/feather_m4can_neotran/.feather_m4_can.test.only
Normal file
111
examples/feather_m4can_neotran/feather_m4can_neotran.ino
Normal file
111
examples/feather_m4can_neotran/feather_m4can_neotran.ino
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
/*
|
||||||
|
* Adafruit Feather M4 CAN Transceiver Example
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <CANSAME5x.h>
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
CANSAME5x CAN;
|
||||||
|
|
||||||
|
Adafruit_NeoPixel strip(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
#define MY_PACKET_ID 0xAF
|
||||||
|
|
||||||
|
uint32_t timestamp;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
//while (!Serial) delay(10);
|
||||||
|
|
||||||
|
Serial.println("CAN NeoPixel Potentiometer RX/TX demo");
|
||||||
|
|
||||||
|
pinMode(PIN_CAN_STANDBY, OUTPUT);
|
||||||
|
digitalWrite(PIN_CAN_STANDBY, false); // turn off STANDBY
|
||||||
|
pinMode(PIN_CAN_BOOSTEN, OUTPUT);
|
||||||
|
digitalWrite(PIN_CAN_BOOSTEN, true); // turn on booster
|
||||||
|
|
||||||
|
strip.begin();
|
||||||
|
strip.setBrightness(50);
|
||||||
|
|
||||||
|
// start the CAN bus at 250 kbps
|
||||||
|
if (!CAN.begin(250000)) {
|
||||||
|
Serial.println("Starting CAN failed!");
|
||||||
|
while (1) delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
timestamp = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// every 100 ms send out a packet
|
||||||
|
if ((millis() - timestamp) > 100) {
|
||||||
|
uint16_t pot = analogRead(A5);
|
||||||
|
// send a packet with the potentiometer value
|
||||||
|
Serial.print("Sending packet with value ");
|
||||||
|
Serial.print(pot);
|
||||||
|
|
||||||
|
CAN.beginPacket(MY_PACKET_ID);
|
||||||
|
CAN.write(pot >> 8);
|
||||||
|
CAN.write(pot & 0xFF);
|
||||||
|
CAN.endPacket();
|
||||||
|
|
||||||
|
Serial.println("...sent!");
|
||||||
|
timestamp = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to parse any incoming packet
|
||||||
|
int packetSize = CAN.parsePacket();
|
||||||
|
|
||||||
|
if (packetSize) {
|
||||||
|
// received a packet
|
||||||
|
Serial.print("Received ");
|
||||||
|
|
||||||
|
if (CAN.packetExtended()) {
|
||||||
|
Serial.print("extended ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CAN.packetRtr()) {
|
||||||
|
// Remote transmission request, packet contains no data
|
||||||
|
Serial.print("RTR ");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("packet with id 0x");
|
||||||
|
Serial.print(CAN.packetId(), HEX);
|
||||||
|
|
||||||
|
if (CAN.packetRtr()) {
|
||||||
|
Serial.print(" and requested length ");
|
||||||
|
Serial.println(CAN.packetDlc());
|
||||||
|
} else {
|
||||||
|
Serial.print(" and length ");
|
||||||
|
Serial.println(packetSize);
|
||||||
|
|
||||||
|
uint8_t receivedData[packetSize];
|
||||||
|
for (int i=0; i<packetSize; i++) {
|
||||||
|
receivedData[i] = CAN.read();
|
||||||
|
Serial.print("0x");
|
||||||
|
Serial.print(receivedData[i], HEX);
|
||||||
|
Serial.print(", ");
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
uint16_t value = (uint16_t)receivedData[0] << 8 | receivedData[1];
|
||||||
|
strip.setPixelColor(0, Wheel(value / 4));
|
||||||
|
strip.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Wheel(byte WheelPos) {
|
||||||
|
WheelPos = 255 - WheelPos;
|
||||||
|
if(WheelPos < 85) {
|
||||||
|
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||||
|
}
|
||||||
|
if(WheelPos < 170) {
|
||||||
|
WheelPos -= 85;
|
||||||
|
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||||
|
}
|
||||||
|
WheelPos -= 170;
|
||||||
|
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||||
|
}
|
||||||
|
|
@ -7,16 +7,17 @@
|
||||||
CANSAME5x CAN;
|
CANSAME5x CAN;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
while (!Serial);
|
while (!Serial) delay(10);
|
||||||
|
|
||||||
Serial.println("CAN Receiver Callback");
|
Serial.println("CAN Receiver Callback");
|
||||||
|
|
||||||
// start the CAN bus at 250 kbps
|
// start the CAN bus at 250 kbps
|
||||||
if (!CAN.begin(250E3)) {
|
if (!CAN.begin(250000)) {
|
||||||
Serial.println("Starting CAN failed!");
|
Serial.println("Starting CAN failed!");
|
||||||
while (1);
|
while (1) delay(10);
|
||||||
}
|
}
|
||||||
|
Serial.println("Starting CAN!");
|
||||||
|
|
||||||
// register the receive callback
|
// register the receive callback
|
||||||
CAN.onReceive(onReceive);
|
CAN.onReceive(onReceive);
|
||||||
|
|
|
||||||
0
examples/feather_m4can_rx/.feather_m4_can.test.only
Normal file
0
examples/feather_m4can_rx/.feather_m4_can.test.only
Normal file
|
|
@ -7,8 +7,8 @@
|
||||||
CANSAME5x CAN;
|
CANSAME5x CAN;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
while (!Serial);
|
while (!Serial) delay(10);
|
||||||
|
|
||||||
Serial.println("CAN Receiver");
|
Serial.println("CAN Receiver");
|
||||||
|
|
||||||
|
|
@ -20,8 +20,9 @@ void setup() {
|
||||||
// start the CAN bus at 250 kbps
|
// start the CAN bus at 250 kbps
|
||||||
if (!CAN.begin(250000)) {
|
if (!CAN.begin(250000)) {
|
||||||
Serial.println("Starting CAN failed!");
|
Serial.println("Starting CAN failed!");
|
||||||
while (1);
|
while (1) delay(10);
|
||||||
}
|
}
|
||||||
|
Serial.println("Starting CAN!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
|
||||||
0
examples/feather_m4can_tx/.feather_m4_can.test.only
Normal file
0
examples/feather_m4can_tx/.feather_m4_can.test.only
Normal file
|
|
@ -7,10 +7,11 @@
|
||||||
CANSAME5x CAN;
|
CANSAME5x CAN;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
while (!Serial);
|
while (!Serial) delay(10);
|
||||||
|
|
||||||
Serial.println("CAN Sender");
|
Serial.println("CAN Sender");
|
||||||
|
|
||||||
pinMode(PIN_CAN_STANDBY, OUTPUT);
|
pinMode(PIN_CAN_STANDBY, OUTPUT);
|
||||||
digitalWrite(PIN_CAN_STANDBY, false); // turn off STANDBY
|
digitalWrite(PIN_CAN_STANDBY, false); // turn off STANDBY
|
||||||
pinMode(PIN_CAN_BOOSTEN, OUTPUT);
|
pinMode(PIN_CAN_BOOSTEN, OUTPUT);
|
||||||
|
|
@ -19,8 +20,9 @@ void setup() {
|
||||||
// start the CAN bus at 250 kbps
|
// start the CAN bus at 250 kbps
|
||||||
if (!CAN.begin(250000)) {
|
if (!CAN.begin(250000)) {
|
||||||
Serial.println("Starting CAN failed!");
|
Serial.println("Starting CAN failed!");
|
||||||
while (1);
|
while (1) delay(10);
|
||||||
}
|
}
|
||||||
|
Serial.println("Starting CAN!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
name=Adafruit CAN
|
name=Adafruit CAN
|
||||||
version=0.2.0
|
version=0.2.3
|
||||||
author=Adafruit
|
author=Adafruit
|
||||||
maintainer=Adafruit <info@adafruit.com>
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
sentence=Arduino library for native CAN.
|
sentence=Arduino library for native CAN.
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,25 @@
|
||||||
|
// Forked from:
|
||||||
// Copyright (c) Sandeep Mistry. All rights reserved.
|
// Copyright (c) Sandeep Mistry. All rights reserved.
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full
|
||||||
|
// license information.
|
||||||
|
|
||||||
#include "CANController.h"
|
#include "CANController.h"
|
||||||
|
|
||||||
CANControllerClass::CANControllerClass() :
|
CANControllerClass::CANControllerClass()
|
||||||
_onReceive(NULL),
|
: _onReceive(NULL),
|
||||||
|
|
||||||
_packetBegun(false),
|
_packetBegun(false), _txId(-1), _txExtended(-1), _txRtr(false), _txDlc(0),
|
||||||
_txId(-1),
|
|
||||||
_txExtended(-1),
|
|
||||||
_txRtr(false),
|
|
||||||
_txDlc(0),
|
|
||||||
_txLength(0),
|
_txLength(0),
|
||||||
|
|
||||||
_rxId(-1),
|
_rxId(-1), _rxExtended(false), _rxRtr(false), _rxDlc(0), _rxLength(0),
|
||||||
_rxExtended(false),
|
_rxIndex(0) {
|
||||||
_rxRtr(false),
|
|
||||||
_rxDlc(0),
|
|
||||||
_rxLength(0),
|
|
||||||
_rxIndex(0)
|
|
||||||
{
|
|
||||||
// overide Stream timeout value
|
// overide Stream timeout value
|
||||||
setTimeout(0);
|
setTimeout(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CANControllerClass::~CANControllerClass()
|
CANControllerClass::~CANControllerClass() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int CANControllerClass::begin(long /*baudRate*/)
|
int CANControllerClass::begin(long /*baudRate*/) {
|
||||||
{
|
|
||||||
_packetBegun = false;
|
_packetBegun = false;
|
||||||
_txId = -1;
|
_txId = -1;
|
||||||
_txRtr = false;
|
_txRtr = false;
|
||||||
|
|
@ -45,12 +35,9 @@ int CANControllerClass::begin(long /*baudRate*/)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANControllerClass::end()
|
void CANControllerClass::end() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int CANControllerClass::beginPacket(int id, int dlc, bool rtr)
|
int CANControllerClass::beginPacket(int id, int dlc, bool rtr) {
|
||||||
{
|
|
||||||
if (id < 0 || id > 0x7FF) {
|
if (id < 0 || id > 0x7FF) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -71,8 +58,7 @@ int CANControllerClass::beginPacket(int id, int dlc, bool rtr)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANControllerClass::beginExtendedPacket(long id, int dlc, bool rtr)
|
int CANControllerClass::beginExtendedPacket(long id, int dlc, bool rtr) {
|
||||||
{
|
|
||||||
if (id < 0 || id > 0x1FFFFFFF) {
|
if (id < 0 || id > 0x1FFFFFFF) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -93,8 +79,7 @@ int CANControllerClass::beginExtendedPacket(long id, int dlc, bool rtr)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANControllerClass::endPacket()
|
int CANControllerClass::endPacket() {
|
||||||
{
|
|
||||||
if (!_packetBegun) {
|
if (!_packetBegun) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -107,38 +92,21 @@ int CANControllerClass::endPacket()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANControllerClass::parsePacket()
|
int CANControllerClass::parsePacket() { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
long CANControllerClass::packetId()
|
long CANControllerClass::packetId() { return _rxId; }
|
||||||
{
|
|
||||||
return _rxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CANControllerClass::packetExtended()
|
bool CANControllerClass::packetExtended() { return _rxExtended; }
|
||||||
{
|
|
||||||
return _rxExtended;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CANControllerClass::packetRtr()
|
bool CANControllerClass::packetRtr() { return _rxRtr; }
|
||||||
{
|
|
||||||
return _rxRtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CANControllerClass::packetDlc()
|
int CANControllerClass::packetDlc() { return _rxDlc; }
|
||||||
{
|
|
||||||
return _rxDlc;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t CANControllerClass::write(uint8_t byte)
|
size_t CANControllerClass::write(uint8_t byte) {
|
||||||
{
|
|
||||||
return write(&byte, sizeof(byte));
|
return write(&byte, sizeof(byte));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CANControllerClass::write(const uint8_t *buffer, size_t size)
|
size_t CANControllerClass::write(const uint8_t *buffer, size_t size) {
|
||||||
{
|
|
||||||
if (!_packetBegun) {
|
if (!_packetBegun) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -153,13 +121,9 @@ size_t CANControllerClass::write(const uint8_t *buffer, size_t size)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANControllerClass::available()
|
int CANControllerClass::available() { return (_rxLength - _rxIndex); }
|
||||||
{
|
|
||||||
return (_rxLength - _rxIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
int CANControllerClass::read()
|
int CANControllerClass::read() {
|
||||||
{
|
|
||||||
if (!available()) {
|
if (!available()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -167,8 +131,7 @@ int CANControllerClass::read()
|
||||||
return _rxData[_rxIndex++];
|
return _rxData[_rxIndex++];
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANControllerClass::peek()
|
int CANControllerClass::peek() {
|
||||||
{
|
|
||||||
if (!available()) {
|
if (!available()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -176,41 +139,20 @@ int CANControllerClass::peek()
|
||||||
return _rxData[_rxIndex];
|
return _rxData[_rxIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANControllerClass::flush()
|
void CANControllerClass::flush() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CANControllerClass::onReceive(void(*callback)(int))
|
void CANControllerClass::onReceive(void (*callback)(int)) {
|
||||||
{
|
|
||||||
_onReceive = callback;
|
_onReceive = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANControllerClass::filter(int /*id*/, int /*mask*/)
|
int CANControllerClass::filter(int /*id*/, int /*mask*/) { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CANControllerClass::filterExtended(long /*id*/, long /*mask*/)
|
int CANControllerClass::filterExtended(long /*id*/, long /*mask*/) { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CANControllerClass::observe()
|
int CANControllerClass::observe() { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CANControllerClass::loopback()
|
int CANControllerClass::loopback() { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CANControllerClass::sleep()
|
int CANControllerClass::sleep() { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CANControllerClass::wakeup()
|
int CANControllerClass::wakeup() { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
|
// Forked from:
|
||||||
// Copyright (c) Sandeep Mistry. All rights reserved.
|
// Copyright (c) Sandeep Mistry. All rights reserved.
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full
|
||||||
|
// license information.
|
||||||
|
|
||||||
#ifndef CAN_CONTROLLER_H
|
#ifndef CAN_CONTROLLER_H
|
||||||
#define CAN_CONTROLLER_H
|
#define CAN_CONTROLLER_H
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full
|
// Licensed under the MIT license. See LICENSE file in the project root for full
|
||||||
// license information.
|
// license information.
|
||||||
|
|
||||||
|
#ifndef CANSAME5x_H
|
||||||
|
#define CANSAME5x_H
|
||||||
|
|
||||||
#include "CANController.h"
|
#include "CANController.h"
|
||||||
|
|
||||||
class CANSAME5x : public CANControllerClass {
|
class CANSAME5x : public CANControllerClass {
|
||||||
|
|
@ -51,3 +54,5 @@ private:
|
||||||
friend void CAN0_Handler(void);
|
friend void CAN0_Handler(void);
|
||||||
friend void CAN1_Handler(void);
|
friend void CAN1_Handler(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue