diff --git a/README.adoc b/README.adoc index b7551d6..64873a1 100644 --- a/README.adoc +++ b/README.adoc @@ -6,9 +6,11 @@ Allows you to draw on your MKR RGB shield. Depends on the ArduinoGraphics librar For more information about this library please visit us at https://www.arduino.cc/en/Reference/ArduinoMKRRGB +Updated: Works with Portenta H7 - one jumper needed - A3 to A5. A4 can be used as-is (after pinMode change). +#define USING_PORTENTA_H7 - make sure this is uncommented in MKRRGBMatrix.h to use the MKR RGB shield in 'bit-bang' mode. == License == -Copyright (c) 2019 Arduino SA. All rights reserved. +Copyright (c) 2020 Arduino SA. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/src/MKRRGBMatrix.cpp b/src/MKRRGBMatrix.cpp index 009fc83..fbda5ce 100644 --- a/src/MKRRGBMatrix.cpp +++ b/src/MKRRGBMatrix.cpp @@ -1,6 +1,6 @@ /* This file is part of the Arduino_MKRRGB library. - Copyright (c) 2019 Arduino SA. All rights reserved. + Copyright (c) 2020 Arduino SA. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -22,7 +22,14 @@ #include "MKRRGBMatrix.h" +#ifndef USING_PORTENTA_H7 static SPIClass SPI_MATRIX(&sercom0, A3, A4, A3, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_0); +#else +#define DATA_PIN A5 // Note - A3 is jumpered to A5 - A3 is input +#define CLOCK_PIN A4 +uint16_t loop_var = 0; +#endif + // This table is based on the formula: gamma = (int)(pow(i / 255.0, gamma) * 255 + offset) // where gamma = 2.5 and offset is 0.5 @@ -68,12 +75,20 @@ int RGBMatrixClass::begin() memset(_buffer, 0x00, 4 + 4 * RGB_MATRIX_WIDTH * RGB_MATRIX_HEIGHT); memset(_buffer + 4 + 4 * RGB_MATRIX_WIDTH * RGB_MATRIX_HEIGHT, 0xff, sizeof(_buffer) - (4 + 4 * RGB_MATRIX_WIDTH * RGB_MATRIX_HEIGHT)); +#ifndef USING_PORTENTA_H7 SPI_MATRIX.begin(); SPI_MATRIX.beginTransaction(SPISettings(12e6, MSBFIRST, SPI_MODE0)); pinPeripheral(A3, PIO_SERCOM_ALT); pinPeripheral(A4, PIO_SERCOM_ALT); - +#else +// pinPeripheral(A4, PIO_OUTPUT); // when pinPeripheral() done. +// pinPeripheral(A5, PIO_OUTPUT); + pinMode(A4, OUTPUT); + pinMode(A5, OUTPUT); + +#endif + brightness(127); return 1; @@ -81,16 +96,25 @@ int RGBMatrixClass::begin() void RGBMatrixClass::end() { + +#ifndef USING_PORTENTA_H7 pinMode(A3, INPUT); pinMode(A4, INPUT); SPI_MATRIX.end(); +#else + pinMode(A5, INPUT); + pinMode(A4, INPUT); +#endif ArduinoGraphics::end(); } void RGBMatrixClass::brightness(uint8_t brightness) { +#ifdef USING_PORTENTA_H7 + uint16_t k = 0; +#endif if (brightness != 0 && brightness < 8) { brightness = 8; } @@ -101,8 +125,13 @@ void RGBMatrixClass::brightness(uint8_t brightness) for (int i = 0; i < (RGB_MATRIX_WIDTH * RGB_MATRIX_HEIGHT); i++) { _buffer[4 + i * 4] = brightness; } - +#ifndef USING_PORTENTA_H7 SPI_MATRIX.transfer(_buffer, sizeof(_buffer)); +#else + loop_var = sizeof(_buffer); + for ( k = 0; k < loop_var; k++) + shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, (_buffer[k])); +#endif } void RGBMatrixClass::beginDraw() @@ -112,9 +141,18 @@ void RGBMatrixClass::beginDraw() void RGBMatrixClass::endDraw() { +#ifdef USING_PORTENTA_H7 + uint16_t k = 0; +#endif ArduinoGraphics::endDraw(); - +#ifndef USING_PORTENTA_H7 SPI_MATRIX.transfer(_buffer, sizeof(_buffer)); +#else + loop_var = sizeof(_buffer); + for ( k = 0; k < loop_var; k++) + shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, (_buffer[k])); + +#endif } void RGBMatrixClass::set(int x, int y, uint8_t r, uint8_t g, uint8_t b) diff --git a/src/MKRRGBMatrix.h b/src/MKRRGBMatrix.h index eb889f0..d69fc79 100644 --- a/src/MKRRGBMatrix.h +++ b/src/MKRRGBMatrix.h @@ -1,6 +1,6 @@ /* This file is part of the Arduino_MKRRGB library. - Copyright (c) 2019 Arduino SA. All rights reserved. + Copyright (c) 2020 Arduino SA. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -25,6 +25,10 @@ #define RGB_MATRIX_WIDTH 12 #define RGB_MATRIX_HEIGHT 7 +// the following is for bit-bang of A4 and A3 jumpered to A5 +// comment if not using the Portenta H7 +// #define USING_PORTENTA_H7 + class RGBMatrixClass : public ArduinoGraphics { public: RGBMatrixClass();