Skip to content

Commit 11299b3

Browse files
committed
Fixing Copilot findings (7)
1 parent 79eb389 commit 11299b3

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

shared-bindings/qspibus/QSPIBus.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,18 @@ static mp_obj_t qspibus_qspibus_obj_reset(mp_obj_t self_in) {
106106
}
107107
static MP_DEFINE_CONST_FUN_OBJ_1(qspibus_qspibus_reset_obj, qspibus_qspibus_obj_reset);
108108

109-
//| def send(self, command: int, data: Optional[ReadableBuffer] = None) -> None:
110-
//| """Send command with optional payload bytes.
111-
//|
112-
//| This mirrors FourWire-style convenience API:
113-
//| - command byte is sent first
114-
//| - optional payload bytes follow
115-
//| """
109+
//| def send(
110+
//| self, command: int, data: ReadableBuffer, *, toggle_every_byte: bool = False
111+
//| ) -> None:
112+
//| """Sends the given command value followed by the full set of data. Display state, such as
113+
//| vertical scroll, set via ``send`` may or may not be reset once the code is done."""
116114
//| ...
117115
//|
118116
static mp_obj_t qspibus_qspibus_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
119117
enum { ARG_command, ARG_data };
120118
static const mp_arg_t allowed_args[] = {
121119
{ MP_QSTR_command, MP_ARG_INT | MP_ARG_REQUIRED },
122-
{ MP_QSTR_data, MP_ARG_OBJ, {.u_obj = mp_const_none} },
120+
{ MP_QSTR_data, MP_ARG_OBJ | MP_ARG_REQUIRED },
123121
};
124122

125123
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
@@ -130,14 +128,8 @@ static mp_obj_t qspibus_qspibus_send(size_t n_args, const mp_obj_t *pos_args, mp
130128

131129
uint8_t command = (uint8_t)mp_arg_validate_int_range(args[ARG_command].u_int, 0, 255, MP_QSTR_command);
132130

133-
const uint8_t *data = NULL;
134-
size_t len = 0;
135-
mp_buffer_info_t data_bufinfo;
136-
if (args[ARG_data].u_obj != mp_const_none) {
137-
mp_get_buffer_raise(args[ARG_data].u_obj, &data_bufinfo, MP_BUFFER_READ);
138-
data = (const uint8_t *)data_bufinfo.buf;
139-
len = data_bufinfo.len;
140-
}
131+
mp_buffer_info_t bufinfo;
132+
mp_get_buffer_raise(args[ARG_data].u_obj, &bufinfo, MP_BUFFER_READ);
141133

142134
// Flush any pending command from a prior write_command() call.
143135
// begin_transaction() returns false while has_pending_command is set,
@@ -151,7 +143,7 @@ static mp_obj_t qspibus_qspibus_send(size_t n_args, const mp_obj_t *pos_args, mp
151143
RUN_BACKGROUND_TASKS;
152144
}
153145
common_hal_qspibus_qspibus_send(MP_OBJ_FROM_PTR(self), DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, &command, 1);
154-
common_hal_qspibus_qspibus_send(MP_OBJ_FROM_PTR(self), DISPLAY_DATA, CHIP_SELECT_UNTOUCHED, data, len);
146+
common_hal_qspibus_qspibus_send(MP_OBJ_FROM_PTR(self), DISPLAY_DATA, CHIP_SELECT_UNTOUCHED, ((uint8_t *)bufinfo.buf), bufinfo.len);
155147
common_hal_qspibus_qspibus_end_transaction(MP_OBJ_FROM_PTR(self));
156148
return mp_const_none;
157149
}

0 commit comments

Comments
 (0)