2019-01-16 15:04:42 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the Micro Python project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
|
|
|
|
*
|
|
|
|
* 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/displayio/ParallelBus.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "lib/utils/context_manager_helpers.h"
|
|
|
|
#include "py/binary.h"
|
|
|
|
#include "py/objproperty.h"
|
|
|
|
#include "py/runtime.h"
|
|
|
|
#include "shared-bindings/microcontroller/Pin.h"
|
|
|
|
#include "shared-bindings/util.h"
|
2019-01-17 17:45:29 -05:00
|
|
|
#include "shared-module/displayio/__init__.h"
|
2019-01-16 15:04:42 -05:00
|
|
|
#include "supervisor/shared/translate.h"
|
|
|
|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| class ParallelBus:
|
2020-05-12 20:15:28 -04:00
|
|
|
//| """Manage updating a display over 8-bit parallel bus in the background while Python code runs. This
|
2020-05-07 10:54:09 -04:00
|
|
|
//| protocol may be refered to as 8080-I Series Parallel Interface in datasheets. It doesn't handle
|
|
|
|
//| display initialization."""
|
2019-01-16 15:04:42 -05:00
|
|
|
//|
|
2020-07-03 14:23:34 -04:00
|
|
|
//| def __init__(self, *, data0: microcontroller.Pin, command: microcontroller.Pin, chip_select: microcontroller.Pin, write: microcontroller.Pin, read: microcontroller.Pin, reset: microcontroller.Pin) -> None:
|
2020-05-07 10:54:09 -04:00
|
|
|
//| """Create a ParallelBus object associated with the given pins. The bus is inferred from data0
|
|
|
|
//| by implying the next 7 additional pins on a given GPIO port.
|
2019-01-16 15:04:42 -05:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| The parallel bus and pins are then in use by the display until `displayio.release_displays()`
|
|
|
|
//| is called even after a reload. (It does this so CircuitPython can use the display after your
|
|
|
|
//| code is done.) So, the first time you initialize a display bus in code.py you should call
|
|
|
|
//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run.
|
2019-01-16 15:04:42 -05:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| :param microcontroller.Pin data0: The first data pin. The rest are implied
|
|
|
|
//| :param microcontroller.Pin command: Data or command pin
|
|
|
|
//| :param microcontroller.Pin chip_select: Chip select pin
|
|
|
|
//| :param microcontroller.Pin write: Write pin
|
|
|
|
//| :param microcontroller.Pin read: Read pin
|
|
|
|
//| :param microcontroller.Pin reset: Reset pin"""
|
|
|
|
//| ...
|
2019-01-18 15:59:23 -05:00
|
|
|
//|
|
2019-01-16 15:04:42 -05:00
|
|
|
STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
2021-02-04 18:33:23 -05:00
|
|
|
enum { ARG_data0, ARG_command, ARG_chip_select, ARG_write, ARG_read, ARG_reset, ARG_frequency };
|
2019-01-17 17:45:29 -05:00
|
|
|
static const mp_arg_t allowed_args[] = {
|
2019-01-18 19:37:06 -05:00
|
|
|
{ MP_QSTR_data0, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
|
|
|
|
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
|
|
|
|
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
|
|
|
|
{ MP_QSTR_write, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
|
|
|
|
{ MP_QSTR_read, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
|
2020-03-06 14:30:30 -05:00
|
|
|
{ MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
|
2021-03-07 13:12:25 -05:00
|
|
|
{ MP_QSTR_frequency, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 60000000 } },
|
2019-01-17 17:45:29 -05:00
|
|
|
};
|
|
|
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
|
|
|
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
|
|
|
|
2020-03-05 16:35:31 -05:00
|
|
|
mcu_pin_obj_t *data0 = validate_obj_is_free_pin(args[ARG_data0].u_obj);
|
|
|
|
mcu_pin_obj_t *command = validate_obj_is_free_pin(args[ARG_command].u_obj);
|
|
|
|
mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj);
|
|
|
|
mcu_pin_obj_t *write = validate_obj_is_free_pin(args[ARG_write].u_obj);
|
|
|
|
mcu_pin_obj_t *read = validate_obj_is_free_pin(args[ARG_read].u_obj);
|
|
|
|
mcu_pin_obj_t *reset = validate_obj_is_free_pin(args[ARG_reset].u_obj);
|
2019-01-17 17:45:29 -05:00
|
|
|
|
2020-03-30 11:47:14 -04:00
|
|
|
displayio_parallelbus_obj_t* self = &allocate_display_bus_or_raise()->parallel_bus;
|
2020-04-21 14:46:03 -04:00
|
|
|
self->base.type = &displayio_parallelbus_type;
|
2019-01-17 17:45:29 -05:00
|
|
|
|
2021-02-04 18:33:23 -05:00
|
|
|
common_hal_displayio_parallelbus_construct(self, data0, command, chip_select, write, read, reset, args[ARG_frequency].u_int);
|
2019-01-17 17:45:29 -05:00
|
|
|
return self;
|
2019-01-16 15:04:42 -05:00
|
|
|
}
|
|
|
|
|
2020-07-03 10:05:14 -04:00
|
|
|
//| def reset(self) -> None:
|
2020-05-07 10:54:09 -04:00
|
|
|
//| """Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
|
|
|
|
//| is available."""
|
|
|
|
//| ...
|
2019-08-21 14:49:49 -04:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
|
2019-08-21 14:49:49 -04:00
|
|
|
STATIC mp_obj_t displayio_parallelbus_obj_reset(mp_obj_t self_in) {
|
|
|
|
displayio_parallelbus_obj_t *self = self_in;
|
|
|
|
|
|
|
|
if (!common_hal_displayio_parallelbus_reset(self)) {
|
|
|
|
mp_raise_RuntimeError(translate("no reset pin available"));
|
|
|
|
}
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
MP_DEFINE_CONST_FUN_OBJ_1(displayio_parallelbus_reset_obj, displayio_parallelbus_obj_reset);
|
|
|
|
|
2020-07-03 13:49:00 -04:00
|
|
|
//| def send(self, command: int, data: ReadableBuffer) -> None:
|
2020-05-07 10:54:09 -04:00
|
|
|
//| """Sends the given command value followed by the full set of data. Display state, such as
|
|
|
|
//| vertical scroll, set via ``send`` may or may not be reset once the code is done."""
|
|
|
|
//| ...
|
2019-02-01 03:32:03 -05:00
|
|
|
//|
|
|
|
|
STATIC mp_obj_t displayio_parallelbus_obj_send(mp_obj_t self, mp_obj_t command_obj, mp_obj_t data_obj) {
|
|
|
|
mp_int_t command_int = MP_OBJ_SMALL_INT_VALUE(command_obj);
|
|
|
|
if (!MP_OBJ_IS_SMALL_INT(command_obj) || command_int > 255 || command_int < 0) {
|
|
|
|
mp_raise_ValueError(translate("Command must be an int between 0 and 255"));
|
|
|
|
}
|
|
|
|
uint8_t command = command_int;
|
|
|
|
mp_buffer_info_t bufinfo;
|
|
|
|
mp_get_buffer_raise(data_obj, &bufinfo, MP_BUFFER_READ);
|
|
|
|
|
2019-03-06 13:45:48 -05:00
|
|
|
// Wait for display bus to be available.
|
|
|
|
while (!common_hal_displayio_parallelbus_begin_transaction(self)) {
|
2019-08-11 09:40:09 -04:00
|
|
|
RUN_BACKGROUND_TASKS;
|
2019-03-06 13:45:48 -05:00
|
|
|
}
|
2019-08-23 18:27:21 -04:00
|
|
|
common_hal_displayio_parallelbus_send(self, DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, &command, 1);
|
|
|
|
common_hal_displayio_parallelbus_send(self, DISPLAY_DATA, CHIP_SELECT_UNTOUCHED, ((uint8_t*) bufinfo.buf), bufinfo.len);
|
2019-02-01 03:32:03 -05:00
|
|
|
common_hal_displayio_parallelbus_end_transaction(self);
|
|
|
|
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
MP_DEFINE_CONST_FUN_OBJ_3(displayio_parallelbus_send_obj, displayio_parallelbus_obj_send);
|
|
|
|
|
2019-01-16 15:04:42 -05:00
|
|
|
STATIC const mp_rom_map_elem_t displayio_parallelbus_locals_dict_table[] = {
|
2019-08-21 14:49:49 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&displayio_parallelbus_reset_obj) },
|
2019-02-01 03:32:03 -05:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_parallelbus_send_obj) },
|
2019-01-16 15:04:42 -05:00
|
|
|
};
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(displayio_parallelbus_locals_dict, displayio_parallelbus_locals_dict_table);
|
|
|
|
|
|
|
|
const mp_obj_type_t displayio_parallelbus_type = {
|
|
|
|
{ &mp_type_type },
|
|
|
|
.name = MP_QSTR_ParallelBus,
|
|
|
|
.make_new = displayio_parallelbus_make_new,
|
|
|
|
.locals_dict = (mp_obj_dict_t*)&displayio_parallelbus_locals_dict,
|
|
|
|
};
|