From 289575a81115310bbc570c1737e662bf7833e3f1 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 8 Jul 2021 15:55:13 -0400 Subject: [PATCH 1/2] Adding rainbow module. --- py/circuitpy_defns.mk | 4 +++ py/circuitpy_mpconfig.h | 8 +++++ py/circuitpy_mpconfig.mk | 3 ++ shared-bindings/_pixelbuf/PixelBuf.c | 2 -- shared-bindings/_pixelbuf/__init__.c | 31 ---------------- shared-bindings/_pixelbuf/__init__.h | 4 --- shared-bindings/rainbow/__init__.c | 54 ++++++++++++++++++++++++++++ shared-bindings/rainbow/__init__.h | 33 +++++++++++++++++ shared-module/rainbow/__init__.c | 42 ++++++++++++++++++++++ 9 files changed, 144 insertions(+), 37 deletions(-) create mode 100644 shared-bindings/rainbow/__init__.c create mode 100644 shared-bindings/rainbow/__init__.h create mode 100644 shared-module/rainbow/__init__.c diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 9756329ac5..c42e2c38f8 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -229,6 +229,9 @@ endif ifeq ($(CIRCUITPY_PIXELBUF),1) SRC_PATTERNS += _pixelbuf/% endif +ifeq ($(CIRCUITPY_RAINBOW),1) +SRC_PATTERNS += rainbow/% +endif ifeq ($(CIRCUITPY_RGBMATRIX),1) SRC_PATTERNS += rgbmatrix/% endif @@ -533,6 +536,7 @@ SRC_SHARED_MODULE_ALL = \ network/__init__.c \ msgpack/__init__.c \ os/__init__.c \ + rainbow/__init__.c \ random/__init__.c \ rgbmatrix/RGBMatrix.c \ rgbmatrix/__init__.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index fdb78d885c..67feef436f 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -644,6 +644,13 @@ extern const struct _mp_obj_module_t pwmio_module; #define PWMIO_MODULE #endif +#if CIRCUITPY_RAINBOW +extern const struct _mp_obj_module_t rainbow_module; +#define RAINBOW_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_rainbow), (mp_obj_t)&rainbow_module }, +#else +#define RAINBOW_MODULE +#endif + #if CIRCUITPY_RANDOM extern const struct _mp_obj_module_t random_module; #define RANDOM_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module }, @@ -918,6 +925,7 @@ extern const struct _mp_obj_module_t msgpack_module; PS2IO_MODULE \ PULSEIO_MODULE \ PWMIO_MODULE \ + RAINBOW_MODULE \ RANDOM_MODULE \ RE_MODULE \ RGBMATRIX_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 0e2c577c69..d601d7df41 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -246,6 +246,9 @@ CFLAGS += -DCIRCUITPY_PULSEIO=$(CIRCUITPY_PULSEIO) CIRCUITPY_PWMIO ?= 1 CFLAGS += -DCIRCUITPY_PWMIO=$(CIRCUITPY_PWMIO) +CIRCUITPY_RAINBOW ?= 1 +CFLAGS += -DCIRCUITPY_RAINBOW=$(CIRCUITPY_RAINBOW) + CIRCUITPY_RANDOM ?= 1 CFLAGS += -DCIRCUITPY_RANDOM=$(CIRCUITPY_RANDOM) diff --git a/shared-bindings/_pixelbuf/PixelBuf.c b/shared-bindings/_pixelbuf/PixelBuf.c index 88c92f8f6c..55055c30c6 100644 --- a/shared-bindings/_pixelbuf/PixelBuf.c +++ b/shared-bindings/_pixelbuf/PixelBuf.c @@ -44,8 +44,6 @@ #include "extmod/ulab/code/ndarray.h" #endif -extern const int32_t colorwheel(float pos); - static void parse_byteorder(mp_obj_t byteorder_obj, pixelbuf_byteorder_details_t *parsed); //| class PixelBuf: diff --git a/shared-bindings/_pixelbuf/__init__.c b/shared-bindings/_pixelbuf/__init__.c index 564e2051b7..a996479ecd 100644 --- a/shared-bindings/_pixelbuf/__init__.c +++ b/shared-bindings/_pixelbuf/__init__.c @@ -41,40 +41,9 @@ //| Byteorders are configured with strings, such as "RGB" or "RGBD".""" // TODO: Pull in docs from pypixelbuf. -//| def colorwheel(n: float) -> int: -//| """C implementation of the common wheel() function found in many examples. -//| Returns the colorwheel RGB value as an integer value for n (usable in :py:class:`PixelBuf`, neopixel, and dotstar).""" -//| ... -//| -//| def wheel(n: float) -> int: -//| """Use of wheel() is deprecated. Please use colorwheel().""" -//| - -STATIC mp_obj_t pixelbuf_colorwheel(mp_obj_t n) { - return MP_OBJ_NEW_SMALL_INT(colorwheel(mp_obj_is_small_int(n) ? MP_OBJ_SMALL_INT_VALUE(n) : mp_obj_get_float(n))); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_colorwheel_obj, pixelbuf_colorwheel); - -const int32_t colorwheel(float pos) { - if (pos > 255) { - pos = pos - ((uint32_t)(pos / 256) * 256); - } - if (pos < 85) { - return (uint8_t)(255 - (pos * 3)) << 16 | (uint8_t)(pos * 3) << 8; - } else if (pos < 170) { - pos -= 85; - return (uint8_t)(255 - (pos * 3)) << 8 | (uint8_t)(pos * 3); - } else { - pos -= 170; - return (uint8_t)(pos * 3) << 16 | (uint8_t)(255 - (pos * 3)); - } -} - STATIC const mp_rom_map_elem_t pixelbuf_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__pixelbuf) }, { MP_ROM_QSTR(MP_QSTR_PixelBuf), MP_ROM_PTR(&pixelbuf_pixelbuf_type) }, - { MP_ROM_QSTR(MP_QSTR_wheel), MP_ROM_PTR(&pixelbuf_colorwheel_obj) }, - { MP_ROM_QSTR(MP_QSTR_colorwheel), MP_ROM_PTR(&pixelbuf_colorwheel_obj) }, }; STATIC MP_DEFINE_CONST_DICT(pixelbuf_module_globals, pixelbuf_module_globals_table); diff --git a/shared-bindings/_pixelbuf/__init__.h b/shared-bindings/_pixelbuf/__init__.h index dea3ca7ef8..28f95c6686 100644 --- a/shared-bindings/_pixelbuf/__init__.h +++ b/shared-bindings/_pixelbuf/__init__.h @@ -27,8 +27,4 @@ #ifndef CP_SHARED_BINDINGS_PIXELBUF_INIT_H #define CP_SHARED_BINDINGS_PIXELBUF_INIT_H -#include "common-hal/digitalio/DigitalInOut.h" - -const int32_t colorwheel(float pos); - #endif // CP_SHARED_BINDINGS_PIXELBUF_INIT_H diff --git a/shared-bindings/rainbow/__init__.c b/shared-bindings/rainbow/__init__.c new file mode 100644 index 0000000000..26c9f2d905 --- /dev/null +++ b/shared-bindings/rainbow/__init__.c @@ -0,0 +1,54 @@ +/* + * This file is part of the CircuitPython project, https://github.com/adafruit/circuitpython + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Kattni Rembor + * + * 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. + */ + +#include "shared-bindings/rainbow/__init__.h" +#include "py/mpconfig.h" +#include "py/obj.h" +//| """`rainbow` module. +//| +//| Provides the `colorwheel()` function.""" +//| +//| def colorwheel(n: float) -> int: +//| """C implementation of the common colorwheel() function found in many examples. +//| Returns the colorwheel RGB value as an integer value for n (usable in neopixel and dotstar).""" +//| ... +//| +STATIC mp_obj_t rainbow_colorwheel(mp_obj_t n) { + return MP_OBJ_NEW_SMALL_INT(colorwheel(mp_obj_is_small_int(n) ? MP_OBJ_SMALL_INT_VALUE(n) : mp_obj_get_float(n))); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(rainbow_colorwheel_obj, rainbow_colorwheel); + +STATIC const mp_rom_map_elem_t rainbow_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_rainbow) }, + { MP_ROM_QSTR(MP_QSTR_colorwheel), MP_ROM_PTR(&rainbow_colorwheel_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(rainbow_module_globals, rainbow_module_globals_table); + +const mp_obj_module_t rainbow_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&rainbow_module_globals, +}; diff --git a/shared-bindings/rainbow/__init__.h b/shared-bindings/rainbow/__init__.h new file mode 100644 index 0000000000..5e1f3f2acb --- /dev/null +++ b/shared-bindings/rainbow/__init__.h @@ -0,0 +1,33 @@ +/* + * This file is part of the CircuitPython project, https://github.com/adafruit/circuitpython + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Kattni Rembor + * + * 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. + */ + +#ifndef CP_SHARED_BINDINGS_RAINBOW_INIT_H +#define CP_SHARED_BINDINGS_RAINBOW_INIT_H +#include + +const int32_t colorwheel(float pos); + +#endif // CP_SHARED_BINDINGS_RAINBOW_INIT_H diff --git a/shared-module/rainbow/__init__.c b/shared-module/rainbow/__init__.c new file mode 100644 index 0000000000..a371992fe3 --- /dev/null +++ b/shared-module/rainbow/__init__.c @@ -0,0 +1,42 @@ +/* + * This file is part of the CircuitPython project, https://github.com/adafruit/circuitpython + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Kattni Rembor + * + * 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. + */ + +#include "shared-bindings/rainbow/__init__.h" + +const int32_t colorwheel(float pos) { + if (pos > 255) { + pos = pos - ((uint32_t)(pos / 256) * 256); + } + if (pos < 85) { + return (uint8_t)(255 - (pos * 3)) << 16 | (uint8_t)(pos * 3) << 8; + } else if (pos < 170) { + pos -= 85; + return (uint8_t)(255 - (pos * 3)) << 8 | (uint8_t)(pos * 3); + } else { + pos -= 170; + return (uint8_t)(pos * 3) << 16 | (uint8_t)(255 - (pos * 3)); + } +} From 825a706135f3de49ae6a6c3bd785da5f8201b68f Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 8 Jul 2021 17:31:10 -0400 Subject: [PATCH 2/2] Turn off MIDI on one build, fix name. --- ports/atmel-samd/boards/escornabot_makech/mpconfigboard.mk | 2 ++ shared-bindings/_pixelbuf/PixelBuf.c | 2 +- shared-bindings/_pixelbuf/PixelBuf.h | 2 +- shared-bindings/_pixelbuf/__init__.c | 2 +- shared-bindings/_pixelbuf/__init__.h | 2 +- shared-module/_pixelbuf/PixelBuf.c | 2 +- shared-module/_pixelbuf/PixelBuf.h | 2 +- 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ports/atmel-samd/boards/escornabot_makech/mpconfigboard.mk b/ports/atmel-samd/boards/escornabot_makech/mpconfigboard.mk index 7317dfbf1b..0d63829c7f 100644 --- a/ports/atmel-samd/boards/escornabot_makech/mpconfigboard.mk +++ b/ports/atmel-samd/boards/escornabot_makech/mpconfigboard.mk @@ -9,3 +9,5 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 + +CIRCUITPY_USB_MIDI = 0 diff --git a/shared-bindings/_pixelbuf/PixelBuf.c b/shared-bindings/_pixelbuf/PixelBuf.c index 55055c30c6..13905c3c29 100644 --- a/shared-bindings/_pixelbuf/PixelBuf.c +++ b/shared-bindings/_pixelbuf/PixelBuf.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Roy Hooper + * Copyright (c) 2018 Rose Hooper * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/_pixelbuf/PixelBuf.h b/shared-bindings/_pixelbuf/PixelBuf.h index 3f2b328391..644f6cd64b 100644 --- a/shared-bindings/_pixelbuf/PixelBuf.h +++ b/shared-bindings/_pixelbuf/PixelBuf.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Roy Hooper + * Copyright (c) 2018 Rose Hooper * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/_pixelbuf/__init__.c b/shared-bindings/_pixelbuf/__init__.c index a996479ecd..9d0cf8c63e 100644 --- a/shared-bindings/_pixelbuf/__init__.c +++ b/shared-bindings/_pixelbuf/__init__.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Roy Hooper + * Copyright (c) 2018 Rose Hooper * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/_pixelbuf/__init__.h b/shared-bindings/_pixelbuf/__init__.h index 28f95c6686..9a84bc68a7 100644 --- a/shared-bindings/_pixelbuf/__init__.h +++ b/shared-bindings/_pixelbuf/__init__.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Roy Hooper + * Copyright (c) 2018 Rose Hooper * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-module/_pixelbuf/PixelBuf.c b/shared-module/_pixelbuf/PixelBuf.c index 161b85b062..63cc409c71 100644 --- a/shared-module/_pixelbuf/PixelBuf.c +++ b/shared-module/_pixelbuf/PixelBuf.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Roy Hooper + * Copyright (c) 2018 Rose Hooper * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-module/_pixelbuf/PixelBuf.h b/shared-module/_pixelbuf/PixelBuf.h index 13139dcc19..b526254f29 100644 --- a/shared-module/_pixelbuf/PixelBuf.h +++ b/shared-module/_pixelbuf/PixelBuf.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Roy Hooper + * Copyright (c) 2018 Rose Hooper * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal