Merge branch 'adafruit:main' into adcdma
This commit is contained in:
commit
5fb5fd0558
@ -104,8 +104,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_PA00,
|
&pin_PA00,
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -84,8 +84,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_PB14, // backlight pin
|
&pin_PB14, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -85,8 +85,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_PA23, // backlight pin
|
&pin_PA23, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -84,7 +84,6 @@ void board_init(void) {
|
|||||||
NULL, // &pin_PA17, // brightness pin
|
NULL, // &pin_PA17, // brightness pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
0.0f, // brightness
|
0.0f, // brightness
|
||||||
false, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
true, // data as commands
|
true, // data as commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -137,8 +137,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
NULL, // backlight pin
|
NULL, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
false, // auto_refresh
|
false, // auto_refresh
|
||||||
|
@ -105,8 +105,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_PA01, // backlight pin
|
&pin_PA01, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -107,8 +107,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_PA01, // backlight pin
|
&pin_PA01, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -94,8 +94,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_PB31, // Backlight pin
|
&pin_PB31, // Backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -111,8 +111,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_PB31, // Backlight pin
|
&pin_PB31, // Backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -102,8 +102,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_PC05, // backlight pin
|
&pin_PC05, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -105,7 +105,6 @@ void board_init(void) {
|
|||||||
NULL,
|
NULL,
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness
|
1.0f, // brightness
|
||||||
false, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data as commands
|
false, // data as commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
//| pixel_format: PixelFormat=PixelFormat.RGB565,
|
//| pixel_format: PixelFormat=PixelFormat.RGB565,
|
||||||
//| frame_size: FrameSize=FrameSize.QQVGA,
|
//| frame_size: FrameSize=FrameSize.QQVGA,
|
||||||
//| jpeg_quality: int=15,
|
//| jpeg_quality: int=15,
|
||||||
//| double_buffered: bool = True,
|
//| framebuffer_count: int = 1,
|
||||||
//| grab_mode: GrabMode = GrabMode.WHEN_EMPTY,
|
//| grab_mode: GrabMode = GrabMode.WHEN_EMPTY,
|
||||||
//| ) -> None:
|
//| ) -> None:
|
||||||
//| """
|
//| """
|
||||||
|
@ -89,8 +89,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO38, // backlight pin
|
&pin_GPIO38, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -95,7 +95,7 @@ void board_init(void) {
|
|||||||
display->base.type = &displayio_display_type;
|
display->base.type = &displayio_display_type;
|
||||||
|
|
||||||
// workaround as board_init() is called before reset_port() in main.c
|
// workaround as board_init() is called before reset_port() in main.c
|
||||||
pwmout_reset();
|
/// pwmout_reset();
|
||||||
|
|
||||||
common_hal_displayio_display_construct(
|
common_hal_displayio_display_construct(
|
||||||
display,
|
display,
|
||||||
@ -118,8 +118,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO45, // backlight pin
|
&pin_GPIO45, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
false, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
@ -128,8 +127,6 @@ void board_init(void) {
|
|||||||
false, // SH1107_addressing
|
false, // SH1107_addressing
|
||||||
50000 // backlight pwm frequency
|
50000 // backlight pwm frequency
|
||||||
);
|
);
|
||||||
|
|
||||||
common_hal_never_reset_pin(&pin_GPIO45); // backlight pin
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool board_requests_safe_mode(void) {
|
bool board_requests_safe_mode(void) {
|
||||||
|
@ -94,8 +94,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO7, // backlight pin
|
&pin_GPIO7, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -118,8 +118,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO45, // backlight pin
|
&pin_GPIO45, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
false, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -97,8 +97,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO21, // backlight pin
|
&pin_GPIO21, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -80,8 +80,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO45, // backlight pin
|
&pin_GPIO45, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -81,8 +81,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO45, // backlight pin
|
&pin_GPIO45, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -111,8 +111,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO48, // backlight pin
|
&pin_GPIO48, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
false, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -108,8 +108,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO9, // backlight pin
|
&pin_GPIO9, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -100,8 +100,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO14, // backlight pin
|
&pin_GPIO14, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -112,8 +112,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO45, // backlight pin
|
&pin_GPIO45, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
false, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -117,8 +117,7 @@ static void display_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO38, // backlight pin
|
&pin_GPIO38, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
false, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -117,8 +117,7 @@ static void display_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO33, // backlight pin
|
&pin_GPIO33, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
false, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -198,8 +198,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
NULL, // There is no backlight pin, defined for now.
|
NULL, // There is no backlight pin, defined for now.
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -54,7 +54,7 @@ void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self,
|
|||||||
self->i2c_num = peripherals_i2c_get_free_num();
|
self->i2c_num = peripherals_i2c_get_free_num();
|
||||||
|
|
||||||
if (self->i2c_num == I2C_NUM_MAX) {
|
if (self->i2c_num == I2C_NUM_MAX) {
|
||||||
mp_raise_ValueError(translate("All I2C targets are in use"));
|
mp_raise_ValueError(translate("All I2C peripherals are in use"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const i2c_config_t i2c_conf = {
|
const i2c_config_t i2c_conf = {
|
||||||
|
@ -84,8 +84,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_P1_05, // backlight pin
|
&pin_P1_05, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -85,8 +85,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_P1_13, // backlight pin
|
&pin_P1_13, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -85,8 +85,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_P0_20, // backlight pin
|
&pin_P0_20, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -84,8 +84,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_P0_02, // backlight pin
|
&pin_P0_02, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -97,7 +97,6 @@ void board_init(void) {
|
|||||||
NULL,
|
NULL,
|
||||||
0x81,
|
0x81,
|
||||||
1.0f, // brightness
|
1.0f, // brightness
|
||||||
false, // auto_brightness
|
|
||||||
true, // single_byte_bounds
|
true, // single_byte_bounds
|
||||||
true, // data as commands
|
true, // data as commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -101,8 +101,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_GPIO12, // backlight pin
|
&pin_GPIO12, // backlight pin
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
true, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
@ -104,8 +104,7 @@ void board_init(void) {
|
|||||||
sizeof(display_init_sequence),
|
sizeof(display_init_sequence),
|
||||||
&pin_PB03,
|
&pin_PB03,
|
||||||
NO_BRIGHTNESS_COMMAND,
|
NO_BRIGHTNESS_COMMAND,
|
||||||
1.0f, // brightness (ignored)
|
1.0f, // brightness
|
||||||
false, // auto_brightness
|
|
||||||
false, // single_byte_bounds
|
false, // single_byte_bounds
|
||||||
false, // data_as_commands
|
false, // data_as_commands
|
||||||
true, // auto_refresh
|
true, // auto_refresh
|
||||||
|
156
py/formatfloat.c
156
py/formatfloat.c
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "py/mpconfig.h"
|
#include "py/mpconfig.h"
|
||||||
|
#include "py/misc.h"
|
||||||
#if MICROPY_FLOAT_IMPL != MICROPY_FLOAT_IMPL_NONE
|
#if MICROPY_FLOAT_IMPL != MICROPY_FLOAT_IMPL_NONE
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -96,7 +97,16 @@ static inline int fp_isless1(float x) {
|
|||||||
#define fp_iszero(x) (x == 0)
|
#define fp_iszero(x) (x == 0)
|
||||||
#define fp_isless1(x) (x < 1.0)
|
#define fp_isless1(x) (x < 1.0)
|
||||||
|
|
||||||
#endif
|
#endif // MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT/DOUBLE
|
||||||
|
|
||||||
|
static inline int fp_ge_eps(FPTYPE x, FPTYPE y) {
|
||||||
|
mp_float_union_t fb_y = {y};
|
||||||
|
// Back off 2 eps.
|
||||||
|
// This is valid for almost all values, but in practice
|
||||||
|
// it's only used when y = 1eX for X>=0.
|
||||||
|
fb_y.i -= 2;
|
||||||
|
return x >= fb_y.f;
|
||||||
|
}
|
||||||
|
|
||||||
static const FPTYPE g_pos_pow[] = {
|
static const FPTYPE g_pos_pow[] = {
|
||||||
#if FPDECEXP > 32
|
#if FPDECEXP > 32
|
||||||
@ -173,6 +183,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
|
|||||||
int num_digits = 0;
|
int num_digits = 0;
|
||||||
const FPTYPE *pos_pow = g_pos_pow;
|
const FPTYPE *pos_pow = g_pos_pow;
|
||||||
const FPTYPE *neg_pow = g_neg_pow;
|
const FPTYPE *neg_pow = g_neg_pow;
|
||||||
|
int signed_e = 0;
|
||||||
|
|
||||||
if (fp_iszero(f)) {
|
if (fp_iszero(f)) {
|
||||||
e = 0;
|
e = 0;
|
||||||
@ -192,31 +203,24 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (fp_isless1(f)) {
|
} else if (fp_isless1(f)) {
|
||||||
// We need to figure out what an integer digit will be used
|
FPTYPE f_mod = f;
|
||||||
// in case 'f' is used (or we revert other format to it below).
|
|
||||||
// As we just tested number to be <1, this is obviously 0,
|
|
||||||
// but we can round it up to 1 below.
|
|
||||||
char first_dig = '0';
|
|
||||||
if (f >= FPROUND_TO_ONE) {
|
|
||||||
first_dig = '1';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build negative exponent
|
// Build negative exponent
|
||||||
for (e = 0, e1 = FPDECEXP; e1; e1 >>= 1, pos_pow++, neg_pow++) {
|
for (e = 0, e1 = FPDECEXP; e1; e1 >>= 1, pos_pow++, neg_pow++) {
|
||||||
if (*neg_pow > f) {
|
if (*neg_pow > f_mod) {
|
||||||
e += e1;
|
e += e1;
|
||||||
f *= *pos_pow;
|
f_mod *= *pos_pow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char e_sign_char = '-';
|
char e_sign_char = '-';
|
||||||
if (fp_isless1(f) && f >= FPROUND_TO_ONE) {
|
if (fp_isless1(f_mod) && f_mod >= FPROUND_TO_ONE) {
|
||||||
f = FPCONST(1.0);
|
f_mod = FPCONST(1.0);
|
||||||
if (e == 0) {
|
if (e == 0) {
|
||||||
e_sign_char = '+';
|
e_sign_char = '+';
|
||||||
}
|
}
|
||||||
} else if (fp_isless1(f)) {
|
} else if (fp_isless1(f_mod)) {
|
||||||
e++;
|
e++;
|
||||||
f *= FPCONST(10.0);
|
f_mod *= FPCONST(10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user specified 'g' format, and e is <= 4, then we'll switch
|
// If the user specified 'g' format, and e is <= 4, then we'll switch
|
||||||
@ -224,8 +228,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
|
|||||||
|
|
||||||
if (fmt == 'f' || (fmt == 'g' && e <= 4)) {
|
if (fmt == 'f' || (fmt == 'g' && e <= 4)) {
|
||||||
fmt = 'f';
|
fmt = 'f';
|
||||||
dec = -1;
|
dec = 0;
|
||||||
*s++ = first_dig;
|
|
||||||
|
|
||||||
if (org_fmt == 'g') {
|
if (org_fmt == 'g') {
|
||||||
prec += (e - 1);
|
prec += (e - 1);
|
||||||
@ -237,13 +240,8 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
num_digits = prec;
|
num_digits = prec;
|
||||||
if (num_digits) {
|
signed_e = 0;
|
||||||
*s++ = '.';
|
++num_digits;
|
||||||
while (--e && num_digits) {
|
|
||||||
*s++ = '0';
|
|
||||||
num_digits--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// For e & g formats, we'll be printing the exponent, so set the
|
// For e & g formats, we'll be printing the exponent, so set the
|
||||||
// sign.
|
// sign.
|
||||||
@ -256,22 +254,29 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
|
|||||||
prec++;
|
prec++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
signed_e = -e;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Build positive exponent
|
// Build positive exponent.
|
||||||
for (e = 0, e1 = FPDECEXP; e1; e1 >>= 1, pos_pow++, neg_pow++) {
|
// We don't modify f at this point to avoid innaccuracies from
|
||||||
if (*pos_pow <= f) {
|
// scaling it. Instead, we find the product of powers of 10
|
||||||
|
// that is not greater than it, and use that to start the
|
||||||
|
// mantissa.
|
||||||
|
FPTYPE u_base = FPCONST(1.0);
|
||||||
|
for (e = 0, e1 = FPDECEXP; e1; e1 >>= 1, pos_pow++) {
|
||||||
|
FPTYPE next_u = u_base * *pos_pow;
|
||||||
|
// fp_ge_eps performs "f >= (next_u - 2eps)" so that if, for
|
||||||
|
// numerical reasons, f is very close to a power of ten but
|
||||||
|
// not strictly equal, we still treat it as that power of 10.
|
||||||
|
// The comparison was failing for maybe 10% of 1eX values, but
|
||||||
|
// although rounding fixed many of them, there were still some
|
||||||
|
// rendering as 9.99999998e(X-1).
|
||||||
|
if (fp_ge_eps(f, next_u)) {
|
||||||
|
u_base = next_u;
|
||||||
e += e1;
|
e += e1;
|
||||||
f *= *neg_pow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// It can be that f was right on the edge of an entry in pos_pow needs to be reduced
|
|
||||||
if ((int)f >= 10) {
|
|
||||||
e += 1;
|
|
||||||
f *= FPCONST(0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the user specified fixed format (fmt == 'f') and e makes the
|
// If the user specified fixed format (fmt == 'f') and e makes the
|
||||||
// number too big to fit into the available buffer, then we'll
|
// number too big to fit into the available buffer, then we'll
|
||||||
// switch to the 'e' format.
|
// switch to the 'e' format.
|
||||||
@ -310,15 +315,15 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
|
|||||||
} else {
|
} else {
|
||||||
e_sign = '+';
|
e_sign = '+';
|
||||||
}
|
}
|
||||||
|
signed_e = e;
|
||||||
}
|
}
|
||||||
if (prec < 0) {
|
if (prec < 0) {
|
||||||
// This can happen when the prec is trimmed to prevent buffer overflow
|
// This can happen when the prec is trimmed to prevent buffer overflow
|
||||||
prec = 0;
|
prec = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We now have num.f as a floating point number between >= 1 and < 10
|
// At this point e contains the absolute value of the power of 10 exponent.
|
||||||
// (or equal to zero), and e contains the absolute value of the power of
|
// (dec + 1) == the number of dgits before the decimal.
|
||||||
// 10 exponent. and (dec + 1) == the number of dgits before the decimal.
|
|
||||||
|
|
||||||
// For e, prec is # digits after the decimal
|
// For e, prec is # digits after the decimal
|
||||||
// For f, prec is # digits after the decimal
|
// For f, prec is # digits after the decimal
|
||||||
@ -336,25 +341,63 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
|
|||||||
num_digits = prec;
|
num_digits = prec;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the digits of the mantissa
|
if (signed_e < 0) {
|
||||||
for (int i = 0; i < num_digits; ++i, --dec) {
|
// The algorithm below treats numbers smaller than 1 by scaling them
|
||||||
int32_t d = (int32_t)f;
|
// repeatedly by 10 to bring the new digit to the top. Our input number
|
||||||
if (d < 0) {
|
// was smaller than 1, so scale it up to be 1 <= f < 10.
|
||||||
*s++ = '0';
|
FPTYPE u_base = FPCONST(1.0);
|
||||||
} else {
|
const FPTYPE *pow_u = g_pos_pow;
|
||||||
*s++ = '0' + d;
|
for (int m = FPDECEXP; m; m >>= 1, pow_u++) {
|
||||||
|
if (m & e) {
|
||||||
|
u_base *= *pow_u;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (dec == 0 && prec > 0) {
|
f *= u_base;
|
||||||
*s++ = '.';
|
|
||||||
}
|
|
||||||
f -= (FPTYPE)d;
|
|
||||||
f *= FPCONST(10.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round
|
int d = 0;
|
||||||
// If we print non-exponential format (i.e. 'f'), but a digit we're going
|
int num_digits_left = num_digits;
|
||||||
// to round by (e) is too far away, then there's nothing to round.
|
for (int digit_index = signed_e; num_digits_left >= 0; --digit_index) {
|
||||||
if ((org_fmt != 'f' || e <= num_digits) && f >= FPCONST(5.0)) {
|
FPTYPE u_base = FPCONST(1.0);
|
||||||
|
if (digit_index > 0) {
|
||||||
|
// Generate 10^digit_index for positive digit_index.
|
||||||
|
const FPTYPE *pow_u = g_pos_pow;
|
||||||
|
int target_index = digit_index;
|
||||||
|
for (int m = FPDECEXP; m; m >>= 1, pow_u++) {
|
||||||
|
if (m & target_index) {
|
||||||
|
u_base *= *pow_u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (d = 0; d < 9; ++d) {
|
||||||
|
// This is essentially "if (f < u_base)", but with 2eps margin
|
||||||
|
// so that if f is just a tiny bit smaller, we treat it as
|
||||||
|
// equal (and accept the additional digit value).
|
||||||
|
if (!fp_ge_eps(f, u_base)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
f -= u_base;
|
||||||
|
}
|
||||||
|
// We calculate one more digit than we display, to use in rounding
|
||||||
|
// below. So only emit the digit if it's one that we display.
|
||||||
|
if (num_digits_left > 0) {
|
||||||
|
// Emit this number (the leading digit).
|
||||||
|
*s++ = '0' + d;
|
||||||
|
if (dec == 0 && prec > 0) {
|
||||||
|
*s++ = '.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
--dec;
|
||||||
|
--num_digits_left;
|
||||||
|
if (digit_index <= 0) {
|
||||||
|
// Once we get below 1.0, we scale up f instead of calculting
|
||||||
|
// negative powers of 10 in u_base. This provides better
|
||||||
|
// renditions of exact decimals like 1/16 etc.
|
||||||
|
f *= FPCONST(10.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Rounding. If the next digit to print is >= 5, round up.
|
||||||
|
if (d >= 5) {
|
||||||
char *rs = s;
|
char *rs = s;
|
||||||
rs--;
|
rs--;
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -394,7 +437,10 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Need at extra digit at the end to make room for the leading '1'
|
// Need at extra digit at the end to make room for the leading '1'
|
||||||
s++;
|
// but if we're at the buffer size limit, just drop the final digit.
|
||||||
|
if ((size_t)(s + 1 - buf) < buf_size) {
|
||||||
|
s++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
char *ss = s;
|
char *ss = s;
|
||||||
while (ss > rs) {
|
while (ss > rs) {
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
//| Most people should not use this class directly. Use a specific display driver instead that will
|
//| Most people should not use this class directly. Use a specific display driver instead that will
|
||||||
//| contain the initialization sequence at minimum."""
|
//| contain the initialization sequence at minimum."""
|
||||||
//|
|
//|
|
||||||
//| def __init__(self, display_bus: _DisplayBus, init_sequence: ReadableBuffer, *, width: int, height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, color_depth: int = 16, grayscale: bool = False, pixels_in_byte_share_row: bool = True, bytes_per_cell: int = 1, reverse_pixels_in_byte: bool = False, set_column_command: int = 0x2a, set_row_command: int = 0x2b, write_ram_command: int = 0x2c, backlight_pin: Optional[microcontroller.Pin] = None, brightness_command: Optional[int] = None, brightness: float = 1.0, auto_brightness: bool = False, single_byte_bounds: bool = False, data_as_commands: bool = False, auto_refresh: bool = True, native_frames_per_second: int = 60, backlight_on_high: bool = True, SH1107_addressing: bool = False) -> None:
|
//| def __init__(self, display_bus: _DisplayBus, init_sequence: ReadableBuffer, *, width: int, height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, color_depth: int = 16, grayscale: bool = False, pixels_in_byte_share_row: bool = True, bytes_per_cell: int = 1, reverse_pixels_in_byte: bool = False, set_column_command: int = 0x2a, set_row_command: int = 0x2b, write_ram_command: int = 0x2c, backlight_pin: Optional[microcontroller.Pin] = None, brightness_command: Optional[int] = None, brightness: float = 1.0, single_byte_bounds: bool = False, data_as_commands: bool = False, auto_refresh: bool = True, native_frames_per_second: int = 60, backlight_on_high: bool = True, SH1107_addressing: bool = False) -> None:
|
||||||
//| r"""Create a Display object on the given display bus (`FourWire`, `ParallelBus` or `I2CDisplay`).
|
//| r"""Create a Display object on the given display bus (`FourWire`, `ParallelBus` or `I2CDisplay`).
|
||||||
//|
|
//|
|
||||||
//| The ``init_sequence`` is bitpacked to minimize the ram impact. Every command begins with a
|
//| The ``init_sequence`` is bitpacked to minimize the ram impact. Every command begins with a
|
||||||
@ -102,8 +102,7 @@
|
|||||||
//| :param int write_ram_command: Command used to write pixels values into the update region. Ignored if data_as_commands is set.
|
//| :param int write_ram_command: Command used to write pixels values into the update region. Ignored if data_as_commands is set.
|
||||||
//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
|
//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
|
||||||
//| :param int brightness_command: Command to set display brightness. Usually available in OLED controllers.
|
//| :param int brightness_command: Command to set display brightness. Usually available in OLED controllers.
|
||||||
//| :param float brightness: Initial display brightness. This value is ignored if auto_brightness is True.
|
//| :param float brightness: Initial display brightness.
|
||||||
//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism.
|
|
||||||
//| :param bool single_byte_bounds: Display column and row commands use single bytes
|
//| :param bool single_byte_bounds: Display column and row commands use single bytes
|
||||||
//| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this.
|
//| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this.
|
||||||
//| :param bool auto_refresh: Automatically refresh the screen
|
//| :param bool auto_refresh: Automatically refresh the screen
|
||||||
@ -122,7 +121,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
|
|||||||
ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word,
|
ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word,
|
||||||
ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command,
|
ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command,
|
||||||
ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command,
|
ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command,
|
||||||
ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands,
|
ARG_brightness, ARG_single_byte_bounds, ARG_data_as_commands,
|
||||||
ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high,
|
ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high,
|
||||||
ARG_SH1107_addressing, ARG_backlight_pwm_frequency };
|
ARG_SH1107_addressing, ARG_backlight_pwm_frequency };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
@ -146,7 +145,6 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
|
|||||||
{ MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
|
{ MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
|
||||||
{ MP_QSTR_brightness_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = NO_BRIGHTNESS_COMMAND} },
|
{ MP_QSTR_brightness_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = NO_BRIGHTNESS_COMMAND} },
|
||||||
{ MP_QSTR_brightness, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} },
|
{ MP_QSTR_brightness, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} },
|
||||||
{ MP_QSTR_auto_brightness, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
|
|
||||||
{ MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
|
{ MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
|
||||||
{ MP_QSTR_data_as_commands, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
|
{ MP_QSTR_data_as_commands, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
|
||||||
{ MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
|
{ MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
|
||||||
@ -196,7 +194,6 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
|
|||||||
MP_OBJ_TO_PTR(backlight_pin),
|
MP_OBJ_TO_PTR(backlight_pin),
|
||||||
args[ARG_brightness_command].u_int,
|
args[ARG_brightness_command].u_int,
|
||||||
brightness,
|
brightness,
|
||||||
args[ARG_auto_brightness].u_bool,
|
|
||||||
args[ARG_single_byte_bounds].u_bool,
|
args[ARG_single_byte_bounds].u_bool,
|
||||||
args[ARG_data_as_commands].u_bool,
|
args[ARG_data_as_commands].u_bool,
|
||||||
args[ARG_auto_refresh].u_bool,
|
args[ARG_auto_refresh].u_bool,
|
||||||
@ -311,9 +308,7 @@ MP_PROPERTY_GETSET(displayio_display_auto_refresh_obj,
|
|||||||
(mp_obj_t)&displayio_display_set_auto_refresh_obj);
|
(mp_obj_t)&displayio_display_set_auto_refresh_obj);
|
||||||
|
|
||||||
//| brightness: float
|
//| brightness: float
|
||||||
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When
|
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness."""
|
||||||
//| `auto_brightness` is True, the value of `brightness` will change automatically.
|
|
||||||
//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False."""
|
|
||||||
//|
|
//|
|
||||||
STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) {
|
STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) {
|
||||||
displayio_display_obj_t *self = native_display(self_in);
|
displayio_display_obj_t *self = native_display(self_in);
|
||||||
@ -327,7 +322,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_brightness_obj, displayio_displa
|
|||||||
|
|
||||||
STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness_obj) {
|
STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness_obj) {
|
||||||
displayio_display_obj_t *self = native_display(self_in);
|
displayio_display_obj_t *self = native_display(self_in);
|
||||||
common_hal_displayio_display_set_auto_brightness(self, false);
|
|
||||||
mp_float_t brightness = mp_obj_get_float(brightness_obj);
|
mp_float_t brightness = mp_obj_get_float(brightness_obj);
|
||||||
if (brightness < 0 || brightness > 1.0) {
|
if (brightness < 0 || brightness > 1.0) {
|
||||||
mp_raise_ValueError(translate("Brightness must be 0-1.0"));
|
mp_raise_ValueError(translate("Brightness must be 0-1.0"));
|
||||||
@ -344,34 +338,6 @@ MP_PROPERTY_GETSET(displayio_display_brightness_obj,
|
|||||||
(mp_obj_t)&displayio_display_get_brightness_obj,
|
(mp_obj_t)&displayio_display_get_brightness_obj,
|
||||||
(mp_obj_t)&displayio_display_set_brightness_obj);
|
(mp_obj_t)&displayio_display_set_brightness_obj);
|
||||||
|
|
||||||
//| auto_brightness: bool
|
|
||||||
//| """True when the display brightness is adjusted automatically, based on an ambient
|
|
||||||
//| light sensor or other method. Note that some displays may have this set to True by default,
|
|
||||||
//| but not actually implement automatic brightness adjustment. `auto_brightness` is set to False
|
|
||||||
//| if `brightness` is set manually."""
|
|
||||||
//|
|
|
||||||
STATIC mp_obj_t displayio_display_obj_get_auto_brightness(mp_obj_t self_in) {
|
|
||||||
displayio_display_obj_t *self = native_display(self_in);
|
|
||||||
return mp_obj_new_bool(common_hal_displayio_display_get_auto_brightness(self));
|
|
||||||
}
|
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_auto_brightness_obj, displayio_display_obj_get_auto_brightness);
|
|
||||||
|
|
||||||
STATIC mp_obj_t displayio_display_obj_set_auto_brightness(mp_obj_t self_in, mp_obj_t auto_brightness) {
|
|
||||||
displayio_display_obj_t *self = native_display(self_in);
|
|
||||||
|
|
||||||
common_hal_displayio_display_set_auto_brightness(self, mp_obj_is_true(auto_brightness));
|
|
||||||
|
|
||||||
return mp_const_none;
|
|
||||||
}
|
|
||||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_set_auto_brightness_obj, displayio_display_obj_set_auto_brightness);
|
|
||||||
|
|
||||||
MP_PROPERTY_GETSET(displayio_display_auto_brightness_obj,
|
|
||||||
(mp_obj_t)&displayio_display_get_auto_brightness_obj,
|
|
||||||
(mp_obj_t)&displayio_display_set_auto_brightness_obj);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//| width: int
|
//| width: int
|
||||||
//| """Gets the width of the board"""
|
//| """Gets the width of the board"""
|
||||||
//|
|
//|
|
||||||
@ -509,7 +475,6 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_auto_refresh), MP_ROM_PTR(&displayio_display_auto_refresh_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_auto_refresh), MP_ROM_PTR(&displayio_display_auto_refresh_obj) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&displayio_display_brightness_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&displayio_display_brightness_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_auto_brightness), MP_ROM_PTR(&displayio_display_auto_brightness_obj) },
|
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_display_width_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_display_width_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) },
|
||||||
|
@ -42,7 +42,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self,
|
|||||||
bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word,
|
bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word,
|
||||||
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command,
|
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command,
|
||||||
uint8_t *init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t *backlight_pin, uint16_t brightness_command,
|
uint8_t *init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t *backlight_pin, uint16_t brightness_command,
|
||||||
mp_float_t brightness, bool auto_brightness,
|
mp_float_t brightness,
|
||||||
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
|
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
|
||||||
bool backlight_on_high, bool SH1107_addressing, uint16_t backlight_pwm_frequency);
|
bool backlight_on_high, bool SH1107_addressing, uint16_t backlight_pwm_frequency);
|
||||||
|
|
||||||
@ -59,9 +59,6 @@ uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t *self);
|
|||||||
uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t *self);
|
uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t *self);
|
||||||
void common_hal_displayio_display_set_rotation(displayio_display_obj_t *self, int rotation);
|
void common_hal_displayio_display_set_rotation(displayio_display_obj_t *self, int rotation);
|
||||||
|
|
||||||
bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t *self);
|
|
||||||
void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t *self, bool auto_brightness);
|
|
||||||
|
|
||||||
bool common_hal_displayio_display_get_dither(displayio_display_obj_t *self);
|
bool common_hal_displayio_display_get_dither(displayio_display_obj_t *self);
|
||||||
void common_hal_displayio_display_set_dither(displayio_display_obj_t *self, bool dither);
|
void common_hal_displayio_display_set_dither(displayio_display_obj_t *self, bool dither);
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
//| import time
|
//| import time
|
||||||
//| import pulseio
|
//| import pulseio
|
||||||
//|
|
//|
|
||||||
//| board.DISPLAY.auto_brightness = False
|
|
||||||
//| board.DISPLAY.brightness = 0
|
//| board.DISPLAY.brightness = 0
|
||||||
//| splash = displayio.Group()
|
//| splash = displayio.Group()
|
||||||
//| board.DISPLAY.show(splash)
|
//| board.DISPLAY.show(splash)
|
||||||
|
@ -173,9 +173,7 @@ MP_PROPERTY_GETSET(framebufferio_framebufferdisplay_auto_refresh_obj,
|
|||||||
(mp_obj_t)&framebufferio_framebufferdisplay_set_auto_refresh_obj);
|
(mp_obj_t)&framebufferio_framebufferdisplay_set_auto_refresh_obj);
|
||||||
|
|
||||||
//| brightness: float
|
//| brightness: float
|
||||||
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When
|
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness."""
|
||||||
//| `auto_brightness` is True, the value of `brightness` will change automatically.
|
|
||||||
//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False."""
|
|
||||||
//|
|
//|
|
||||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_brightness(mp_obj_t self_in) {
|
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_brightness(mp_obj_t self_in) {
|
||||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
||||||
@ -189,7 +187,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_brightness_obj, f
|
|||||||
|
|
||||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness_obj) {
|
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness_obj) {
|
||||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
||||||
common_hal_framebufferio_framebufferdisplay_set_auto_brightness(self, false);
|
|
||||||
mp_float_t brightness = mp_obj_get_float(brightness_obj);
|
mp_float_t brightness = mp_obj_get_float(brightness_obj);
|
||||||
if (brightness < 0.0f || brightness > 1.0f) {
|
if (brightness < 0.0f || brightness > 1.0f) {
|
||||||
mp_raise_ValueError(translate("Brightness must be 0-1.0"));
|
mp_raise_ValueError(translate("Brightness must be 0-1.0"));
|
||||||
@ -206,34 +203,6 @@ MP_PROPERTY_GETSET(framebufferio_framebufferdisplay_brightness_obj,
|
|||||||
(mp_obj_t)&framebufferio_framebufferdisplay_get_brightness_obj,
|
(mp_obj_t)&framebufferio_framebufferdisplay_get_brightness_obj,
|
||||||
(mp_obj_t)&framebufferio_framebufferdisplay_set_brightness_obj);
|
(mp_obj_t)&framebufferio_framebufferdisplay_set_brightness_obj);
|
||||||
|
|
||||||
//| auto_brightness: bool
|
|
||||||
//| """True when the display brightness is adjusted automatically, based on an ambient
|
|
||||||
//| light sensor or other method. Note that some displays may have this set to True by default,
|
|
||||||
//| but not actually implement automatic brightness adjustment. `auto_brightness` is set to False
|
|
||||||
//| if `brightness` is set manually."""
|
|
||||||
//|
|
|
||||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_auto_brightness(mp_obj_t self_in) {
|
|
||||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
|
||||||
return mp_obj_new_bool(common_hal_framebufferio_framebufferdisplay_get_auto_brightness(self));
|
|
||||||
}
|
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_auto_brightness_obj, framebufferio_framebufferdisplay_obj_get_auto_brightness);
|
|
||||||
|
|
||||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_set_auto_brightness(mp_obj_t self_in, mp_obj_t auto_brightness) {
|
|
||||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
|
||||||
|
|
||||||
bool ok = common_hal_framebufferio_framebufferdisplay_set_auto_brightness(self, mp_obj_is_true(auto_brightness));
|
|
||||||
if (!ok) {
|
|
||||||
mp_raise_RuntimeError(translate("Brightness not adjustable"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return mp_const_none;
|
|
||||||
}
|
|
||||||
MP_DEFINE_CONST_FUN_OBJ_2(framebufferio_framebufferdisplay_set_auto_brightness_obj, framebufferio_framebufferdisplay_obj_set_auto_brightness);
|
|
||||||
|
|
||||||
MP_PROPERTY_GETSET(framebufferio_framebufferdisplay_auto_brightness_obj,
|
|
||||||
(mp_obj_t)&framebufferio_framebufferdisplay_get_auto_brightness_obj,
|
|
||||||
(mp_obj_t)&framebufferio_framebufferdisplay_set_auto_brightness_obj);
|
|
||||||
|
|
||||||
//| width: int
|
//| width: int
|
||||||
//| """Gets the width of the framebuffer"""
|
//| """Gets the width of the framebuffer"""
|
||||||
//|
|
//|
|
||||||
@ -374,7 +343,6 @@ STATIC const mp_rom_map_elem_t framebufferio_framebufferdisplay_locals_dict_tabl
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_auto_refresh), MP_ROM_PTR(&framebufferio_framebufferdisplay_auto_refresh_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_auto_refresh), MP_ROM_PTR(&framebufferio_framebufferdisplay_auto_refresh_obj) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&framebufferio_framebufferdisplay_brightness_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&framebufferio_framebufferdisplay_brightness_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_auto_brightness), MP_ROM_PTR(&framebufferio_framebufferdisplay_auto_brightness_obj) },
|
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&framebufferio_framebufferdisplay_width_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&framebufferio_framebufferdisplay_width_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&framebufferio_framebufferdisplay_height_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&framebufferio_framebufferdisplay_height_obj) },
|
||||||
|
@ -55,9 +55,6 @@ uint16_t common_hal_framebufferio_framebufferdisplay_get_height(framebufferio_fr
|
|||||||
uint16_t common_hal_framebufferio_framebufferdisplay_get_rotation(framebufferio_framebufferdisplay_obj_t *self);
|
uint16_t common_hal_framebufferio_framebufferdisplay_get_rotation(framebufferio_framebufferdisplay_obj_t *self);
|
||||||
void common_hal_framebufferio_framebufferdisplay_set_rotation(framebufferio_framebufferdisplay_obj_t *self, int rotation);
|
void common_hal_framebufferio_framebufferdisplay_set_rotation(framebufferio_framebufferdisplay_obj_t *self, int rotation);
|
||||||
|
|
||||||
bool common_hal_framebufferio_framebufferdisplay_get_auto_brightness(framebufferio_framebufferdisplay_obj_t *self);
|
|
||||||
bool common_hal_framebufferio_framebufferdisplay_set_auto_brightness(framebufferio_framebufferdisplay_obj_t *self, bool auto_brightness);
|
|
||||||
|
|
||||||
mp_float_t common_hal_framebufferio_framebufferdisplay_get_brightness(framebufferio_framebufferdisplay_obj_t *self);
|
mp_float_t common_hal_framebufferio_framebufferdisplay_get_brightness(framebufferio_framebufferdisplay_obj_t *self);
|
||||||
bool common_hal_framebufferio_framebufferdisplay_set_brightness(framebufferio_framebufferdisplay_obj_t *self, mp_float_t brightness);
|
bool common_hal_framebufferio_framebufferdisplay_set_brightness(framebufferio_framebufferdisplay_obj_t *self, mp_float_t brightness);
|
||||||
|
|
||||||
|
@ -34,18 +34,28 @@
|
|||||||
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in every byte"""
|
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in every byte"""
|
||||||
//|
|
//|
|
||||||
//| EVEN_BYTES: PixelPolicy
|
//| EVEN_BYTES: PixelPolicy
|
||||||
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 0, 2, …, and ignored bytes in positions 1, 3, …. This can decode directly from YUV images where the even bytes hold the Y (luminance) data."""
|
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 0, 2, …, and ignored bytes in positions 1, 3, …. This can decode directly from YUV images where the even bytes hold the Y (luminance) data."""
|
||||||
//|
|
//|
|
||||||
//| ODD_BYTES: PixelPolicy
|
//| ODD_BYTES: PixelPolicy
|
||||||
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 1, 3, …, and ignored bytes in positions 0, 2, …. This can decode directly from YUV images where the odd bytes hold the Y (luminance) data"""
|
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 1, 3, …, and ignored bytes in positions 0, 2, …. This can decode directly from YUV images where the odd bytes hold the Y (luminance) data"""
|
||||||
|
//|
|
||||||
|
//| RGB565_SWAPPED: PixelPolicy
|
||||||
|
//| """The input buffer to `QRDecoder.decode` consists of RGB565 values in byte-swapped order. Most cameras produce data in byte-swapped order. The green component is used."""
|
||||||
|
//|
|
||||||
|
//| RGB565: PixelPolicy
|
||||||
|
//| """The input buffer to `QRDecoder.decode` consists of RGB565 values in native order. The green component is used."""
|
||||||
//|
|
//|
|
||||||
|
|
||||||
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVERY_BYTE, QRIO_EVERY_BYTE);
|
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVERY_BYTE, QRIO_EVERY_BYTE);
|
||||||
|
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, RGB565, QRIO_RGB565);
|
||||||
|
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, RGB565_SWAPPED, QRIO_RGB565_SWAPPED);
|
||||||
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVEN_BYTES, QRIO_EVEN_BYTES);
|
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVEN_BYTES, QRIO_EVEN_BYTES);
|
||||||
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, ODD_BYTES, QRIO_EVEN_BYTES);
|
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, ODD_BYTES, QRIO_EVEN_BYTES);
|
||||||
|
|
||||||
MAKE_ENUM_MAP(qrio_pixel_policy) {
|
MAKE_ENUM_MAP(qrio_pixel_policy) {
|
||||||
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVERY_BYTE),
|
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVERY_BYTE),
|
||||||
|
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, RGB565),
|
||||||
|
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, RGB565_SWAPPED),
|
||||||
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVEN_BYTES),
|
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVEN_BYTES),
|
||||||
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, ODD_BYTES),
|
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, ODD_BYTES),
|
||||||
};
|
};
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
extern const mp_obj_type_t qrio_pixel_policy_type;
|
extern const mp_obj_type_t qrio_pixel_policy_type;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
QRIO_EVERY_BYTE, QRIO_EVEN_BYTES, QRIO_ODD_BYTES
|
QRIO_EVERY_BYTE, QRIO_EVEN_BYTES, QRIO_ODD_BYTES, QRIO_RGB565, QRIO_RGB565_SWAPPED
|
||||||
} qrio_pixel_policy_t;
|
} qrio_pixel_policy_t;
|
||||||
|
|
||||||
extern const cp_enum_obj_t qrio_pixel_policy_EVERY_BYTE_obj;
|
extern const cp_enum_obj_t qrio_pixel_policy_EVERY_BYTE_obj;
|
||||||
|
@ -51,7 +51,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self,
|
|||||||
uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word, uint8_t set_column_command,
|
uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word, uint8_t set_column_command,
|
||||||
uint8_t set_row_command, uint8_t write_ram_command,
|
uint8_t set_row_command, uint8_t write_ram_command,
|
||||||
uint8_t *init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t *backlight_pin,
|
uint8_t *init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t *backlight_pin,
|
||||||
uint16_t brightness_command, mp_float_t brightness, bool auto_brightness,
|
uint16_t brightness_command, mp_float_t brightness,
|
||||||
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
|
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
|
||||||
bool backlight_on_high, bool SH1107_addressing, uint16_t backlight_pwm_frequency) {
|
bool backlight_on_high, bool SH1107_addressing, uint16_t backlight_pwm_frequency) {
|
||||||
|
|
||||||
@ -70,7 +70,6 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self,
|
|||||||
self->set_row_command = set_row_command;
|
self->set_row_command = set_row_command;
|
||||||
self->write_ram_command = write_ram_command;
|
self->write_ram_command = write_ram_command;
|
||||||
self->brightness_command = brightness_command;
|
self->brightness_command = brightness_command;
|
||||||
self->auto_brightness = auto_brightness;
|
|
||||||
self->first_manual_refresh = !auto_refresh;
|
self->first_manual_refresh = !auto_refresh;
|
||||||
self->data_as_commands = data_as_commands;
|
self->data_as_commands = data_as_commands;
|
||||||
self->backlight_on_high = backlight_on_high;
|
self->backlight_on_high = backlight_on_high;
|
||||||
@ -132,12 +131,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self,
|
|||||||
common_hal_never_reset_pin(backlight_pin);
|
common_hal_never_reset_pin(backlight_pin);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (!self->auto_brightness && (self->backlight_inout.base.type != &mp_type_NoneType ||
|
|
||||||
brightness_command != NO_BRIGHTNESS_COMMAND)) {
|
common_hal_displayio_display_set_brightness(self, brightness);
|
||||||
common_hal_displayio_display_set_brightness(self, brightness);
|
|
||||||
} else {
|
|
||||||
self->current_brightness = -1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the group after initialization otherwise we may send pixels while we delay in
|
// Set the group after initialization otherwise we may send pixels while we delay in
|
||||||
// initialization.
|
// initialization.
|
||||||
@ -157,20 +152,11 @@ uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t *self)
|
|||||||
return displayio_display_core_get_height(&self->core);
|
return displayio_display_core_get_height(&self->core);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t *self) {
|
|
||||||
return self->auto_brightness;
|
|
||||||
}
|
|
||||||
|
|
||||||
void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t *self, bool auto_brightness) {
|
|
||||||
self->auto_brightness = auto_brightness;
|
|
||||||
}
|
|
||||||
|
|
||||||
mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t *self) {
|
mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t *self) {
|
||||||
return self->current_brightness;
|
return self->current_brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self, mp_float_t brightness) {
|
bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self, mp_float_t brightness) {
|
||||||
self->updating_backlight = true;
|
|
||||||
if (!self->backlight_on_high) {
|
if (!self->backlight_on_high) {
|
||||||
brightness = 1.0 - brightness;
|
brightness = 1.0 - brightness;
|
||||||
}
|
}
|
||||||
@ -209,7 +195,6 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
self->updating_backlight = false;
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
self->current_brightness = brightness;
|
self->current_brightness = brightness;
|
||||||
}
|
}
|
||||||
@ -413,23 +398,8 @@ void common_hal_displayio_display_set_auto_refresh(displayio_display_obj_t *self
|
|||||||
self->auto_refresh = auto_refresh;
|
self->auto_refresh = auto_refresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void _update_backlight(displayio_display_obj_t *self) {
|
|
||||||
if (!self->auto_brightness || self->updating_backlight) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (supervisor_ticks_ms64() - self->last_backlight_refresh < 100) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// TODO(tannewt): Fade the backlight based on its existing value and a target value. The target
|
|
||||||
// should account for ambient light when possible.
|
|
||||||
common_hal_displayio_display_set_brightness(self, 1.0);
|
|
||||||
|
|
||||||
self->last_backlight_refresh = supervisor_ticks_ms64();
|
|
||||||
}
|
|
||||||
|
|
||||||
void displayio_display_background(displayio_display_obj_t *self) {
|
void displayio_display_background(displayio_display_obj_t *self) {
|
||||||
_update_backlight(self);
|
common_hal_displayio_display_set_brightness(self, 1.0);
|
||||||
|
|
||||||
if (self->auto_refresh && (supervisor_ticks_ms64() - self->core.last_refresh) > self->native_ms_per_frame) {
|
if (self->auto_refresh && (supervisor_ticks_ms64() - self->core.last_refresh) > self->native_ms_per_frame) {
|
||||||
_refresh_display(self);
|
_refresh_display(self);
|
||||||
}
|
}
|
||||||
@ -452,7 +422,6 @@ void release_display(displayio_display_obj_t *self) {
|
|||||||
|
|
||||||
void reset_display(displayio_display_obj_t *self) {
|
void reset_display(displayio_display_obj_t *self) {
|
||||||
common_hal_displayio_display_set_auto_refresh(self, true);
|
common_hal_displayio_display_set_auto_refresh(self, true);
|
||||||
self->auto_brightness = true;
|
|
||||||
common_hal_displayio_display_show(self, NULL);
|
common_hal_displayio_display_show(self, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,6 @@ typedef struct {
|
|||||||
pwmio_pwmout_obj_t backlight_pwm;
|
pwmio_pwmout_obj_t backlight_pwm;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
uint64_t last_backlight_refresh;
|
|
||||||
uint64_t last_refresh_call;
|
uint64_t last_refresh_call;
|
||||||
mp_float_t current_brightness;
|
mp_float_t current_brightness;
|
||||||
uint16_t brightness_command;
|
uint16_t brightness_command;
|
||||||
@ -57,8 +56,6 @@ typedef struct {
|
|||||||
bool auto_refresh;
|
bool auto_refresh;
|
||||||
bool first_manual_refresh;
|
bool first_manual_refresh;
|
||||||
bool data_as_commands;
|
bool data_as_commands;
|
||||||
bool auto_brightness;
|
|
||||||
bool updating_backlight;
|
|
||||||
bool backlight_on_high;
|
bool backlight_on_high;
|
||||||
// new quirk for sh1107
|
// new quirk for sh1107
|
||||||
bool SH1107_addressing;
|
bool SH1107_addressing;
|
||||||
|
@ -113,20 +113,6 @@ uint16_t common_hal_framebufferio_framebufferdisplay_get_height(framebufferio_fr
|
|||||||
return displayio_display_core_get_height(&self->core);
|
return displayio_display_core_get_height(&self->core);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_framebufferio_framebufferdisplay_get_auto_brightness(framebufferio_framebufferdisplay_obj_t *self) {
|
|
||||||
if (self->framebuffer_protocol->get_auto_brightness) {
|
|
||||||
return self->framebuffer_protocol->get_auto_brightness(self->framebuffer);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool common_hal_framebufferio_framebufferdisplay_set_auto_brightness(framebufferio_framebufferdisplay_obj_t *self, bool auto_brightness) {
|
|
||||||
if (self->framebuffer_protocol->set_auto_brightness) {
|
|
||||||
return self->framebuffer_protocol->set_auto_brightness(self->framebuffer, auto_brightness);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mp_float_t common_hal_framebufferio_framebufferdisplay_get_brightness(framebufferio_framebufferdisplay_obj_t *self) {
|
mp_float_t common_hal_framebufferio_framebufferdisplay_get_brightness(framebufferio_framebufferdisplay_obj_t *self) {
|
||||||
if (self->framebuffer_protocol->get_brightness) {
|
if (self->framebuffer_protocol->get_brightness) {
|
||||||
return self->framebuffer_protocol->get_brightness(self->framebuffer);
|
return self->framebuffer_protocol->get_brightness(self->framebuffer);
|
||||||
|
@ -43,7 +43,6 @@ typedef struct {
|
|||||||
mp_obj_t framebuffer;
|
mp_obj_t framebuffer;
|
||||||
const struct _framebuffer_p_t *framebuffer_protocol;
|
const struct _framebuffer_p_t *framebuffer_protocol;
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
uint64_t last_backlight_refresh;
|
|
||||||
uint64_t last_refresh_call;
|
uint64_t last_refresh_call;
|
||||||
uint16_t native_frames_per_second;
|
uint16_t native_frames_per_second;
|
||||||
uint16_t native_ms_per_frame;
|
uint16_t native_ms_per_frame;
|
||||||
@ -61,10 +60,8 @@ void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisp
|
|||||||
|
|
||||||
mp_obj_t common_hal_framebufferio_framebufferdisplay_get_framebuffer(framebufferio_framebufferdisplay_obj_t *self);
|
mp_obj_t common_hal_framebufferio_framebufferdisplay_get_framebuffer(framebufferio_framebufferdisplay_obj_t *self);
|
||||||
|
|
||||||
typedef bool (*framebuffer_get_auto_brightness_fun)(mp_obj_t);
|
|
||||||
typedef bool (*framebuffer_get_reverse_pixels_in_byte_fun)(mp_obj_t);
|
typedef bool (*framebuffer_get_reverse_pixels_in_byte_fun)(mp_obj_t);
|
||||||
typedef bool (*framebuffer_get_reverse_pixels_in_word_fun)(mp_obj_t);
|
typedef bool (*framebuffer_get_reverse_pixels_in_word_fun)(mp_obj_t);
|
||||||
typedef bool (*framebuffer_set_auto_brightness_fun)(mp_obj_t, bool);
|
|
||||||
typedef bool (*framebuffer_set_brightness_fun)(mp_obj_t, mp_float_t);
|
typedef bool (*framebuffer_set_brightness_fun)(mp_obj_t, mp_float_t);
|
||||||
typedef int (*framebuffer_get_bytes_per_cell_fun)(mp_obj_t);
|
typedef int (*framebuffer_get_bytes_per_cell_fun)(mp_obj_t);
|
||||||
typedef int (*framebuffer_get_color_depth_fun)(mp_obj_t);
|
typedef int (*framebuffer_get_color_depth_fun)(mp_obj_t);
|
||||||
@ -105,9 +102,6 @@ typedef struct _framebuffer_p_t {
|
|||||||
framebuffer_get_brightness_fun get_brightness;
|
framebuffer_get_brightness_fun get_brightness;
|
||||||
framebuffer_set_brightness_fun set_brightness;
|
framebuffer_set_brightness_fun set_brightness;
|
||||||
|
|
||||||
// Optional -- default is no automatic brightness control
|
|
||||||
framebuffer_get_auto_brightness_fun get_auto_brightness;
|
|
||||||
framebuffer_set_auto_brightness_fun set_auto_brightness;
|
|
||||||
} framebuffer_p_t;
|
} framebuffer_p_t;
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_FRAMEBUFFERDISPLAY_H
|
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_FRAMEBUFFERDISPLAY_H
|
||||||
|
@ -104,6 +104,20 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co
|
|||||||
uint8_t *src = bufinfo->buf;
|
uint8_t *src = bufinfo->buf;
|
||||||
|
|
||||||
switch (policy) {
|
switch (policy) {
|
||||||
|
case QRIO_RGB565: {
|
||||||
|
uint16_t *src16 = bufinfo->buf;
|
||||||
|
for (int i = 0; i < width * height; i++) {
|
||||||
|
framebuffer[i] = (src16[i] >> 3) & 0xfc;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QRIO_RGB565_SWAPPED: {
|
||||||
|
uint16_t *src16 = bufinfo->buf;
|
||||||
|
for (int i = 0; i < width * height; i++) {
|
||||||
|
framebuffer[i] = (__builtin_bswap16(src16[i]) >> 3) & 0xfc;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case QRIO_EVERY_BYTE:
|
case QRIO_EVERY_BYTE:
|
||||||
memcpy(framebuffer, src, width * height);
|
memcpy(framebuffer, src, width * height);
|
||||||
break;
|
break;
|
||||||
@ -116,6 +130,7 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co
|
|||||||
for (int i = 0; i < width * height; i++) {
|
for (int i = 0; i < width * height; i++) {
|
||||||
framebuffer[i] = src[2 * i];
|
framebuffer[i] = src[2 * i];
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
quirc_end(self->quirc);
|
quirc_end(self->quirc);
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1><a href="/"><img src="/favicon.ico"/></a> <span id="path"></span></h1>
|
<h1><a href="/"><img src="/favicon.ico"/></a> <span id="path"></span></h1>
|
||||||
<div id="usbwarning" style="display: none;">🛈 USB is using the storage. Only allowing reads. See <a href="https://learn.adafruit.com/circuitpython-essentials/circuitpython-storage">the CircuitPython Essentials: Storage guide</a> for details.</div>
|
<div id="usbwarning" style="display: none;">ℹ️ USB is using the storage. Only allowing reads. See <a href="https://learn.adafruit.com/circuitpython-essentials/circuitpython-storage">the CircuitPython Essentials: Storage guide</a> for details.</div>
|
||||||
<template id="row"><tr><td></td><td></td><td><a></a></td><td></td><td><button class="delete">🗑️</button></td><td><a class="edit_link" href="">Edit</a></td></tr></template>
|
<template id="row"><tr><td></td><td></td><td><a></a></td><td></td><td><button class="delete">🗑️</button></td><td><a class="edit_link" href="">Edit</a></td></tr></template>
|
||||||
<table>
|
<table>
|
||||||
<thead><tr><th>Type</th><th>Size</th><th>Path</th><th>Modified</th><th></th></tr></thead>
|
<thead><tr><th>Type</th><th>Size</th><th>Path</th><th>Modified</th><th></th></tr></thead>
|
||||||
@ -18,5 +18,5 @@
|
|||||||
<hr>
|
<hr>
|
||||||
<input type="file" id="files" multiple><button type="submit" id="upload">Upload</button>
|
<input type="file" id="files" multiple><button type="submit" id="upload">Upload</button>
|
||||||
<hr>
|
<hr>
|
||||||
+🗀 <input type="text" id="name"><button type="submit" id="mkdir">Create Directory</button>
|
+📁 <input type="text" id="name"><button type="submit" id="mkdir">Create Directory</button>
|
||||||
</body></html>
|
</body></html>
|
||||||
|
@ -6,6 +6,15 @@ var current_path;
|
|||||||
var editable = undefined;
|
var editable = undefined;
|
||||||
|
|
||||||
async function refresh_list() {
|
async function refresh_list() {
|
||||||
|
|
||||||
|
function compareValues(a, b) {
|
||||||
|
if (a.directory == b.directory && a.name.toLowerCase() === b.name.toLowerCase()) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return a.directory.toString().substring(3,4)+a.name.toLowerCase() < b.directory.toString().substring(3,4)+b.name.toLowerCase() ? -1 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
current_path = window.location.hash.substr(1);
|
current_path = window.location.hash.substr(1);
|
||||||
if (current_path == "") {
|
if (current_path == "") {
|
||||||
current_path = "/";
|
current_path = "/";
|
||||||
@ -46,7 +55,7 @@ async function refresh_list() {
|
|||||||
if (window.location.path != "/fs/") {
|
if (window.location.path != "/fs/") {
|
||||||
var clone = template.content.cloneNode(true);
|
var clone = template.content.cloneNode(true);
|
||||||
var td = clone.querySelectorAll("td");
|
var td = clone.querySelectorAll("td");
|
||||||
td[0].textContent = "🗀";
|
td[0].textContent = "📁";
|
||||||
var path = clone.querySelector("a");
|
var path = clone.querySelector("a");
|
||||||
let parent = new URL("..", "file://" + current_path);
|
let parent = new URL("..", "file://" + current_path);
|
||||||
path.href = "#" + parent.pathname;
|
path.href = "#" + parent.pathname;
|
||||||
@ -56,11 +65,13 @@ async function refresh_list() {
|
|||||||
new_children.push(clone);
|
new_children.push(clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.sort(compareValues);
|
||||||
|
|
||||||
for (const f of data) {
|
for (const f of data) {
|
||||||
// Clone the new row and insert it into the table
|
// Clone the new row and insert it into the table
|
||||||
var clone = template.content.cloneNode(true);
|
var clone = template.content.cloneNode(true);
|
||||||
var td = clone.querySelectorAll("td");
|
var td = clone.querySelectorAll("td");
|
||||||
var icon = "⬇";
|
var icon = "⬇️";
|
||||||
var file_path = current_path + f.name;
|
var file_path = current_path + f.name;
|
||||||
let api_url = new URL("/fs" + file_path, url_base);
|
let api_url = new URL("/fs" + file_path, url_base);
|
||||||
let edit_url = "/edit/#" + file_path;
|
let edit_url = "/edit/#" + file_path;
|
||||||
@ -72,12 +83,12 @@ async function refresh_list() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (f.directory) {
|
if (f.directory) {
|
||||||
icon = "🗀";
|
icon = "📁";
|
||||||
} else if(f.name.endsWith(".txt") ||
|
} else if(f.name.endsWith(".txt") ||
|
||||||
f.name.endsWith(".py") ||
|
f.name.endsWith(".py") ||
|
||||||
f.name.endsWith(".js") ||
|
f.name.endsWith(".js") ||
|
||||||
f.name.endsWith(".json")) {
|
f.name.endsWith(".json")) {
|
||||||
icon = "🖹";
|
icon = "📄";
|
||||||
} else if (f.name.endsWith(".html")) {
|
} else if (f.name.endsWith(".html")) {
|
||||||
icon = "🌐";
|
icon = "🌐";
|
||||||
}
|
}
|
||||||
@ -92,9 +103,11 @@ async function refresh_list() {
|
|||||||
delete_button.disabled = !editable;
|
delete_button.disabled = !editable;
|
||||||
delete_button.onclick = del;
|
delete_button.onclick = del;
|
||||||
|
|
||||||
edit_url = new URL(edit_url, url_base);
|
if (editable && !f.directory) {
|
||||||
let edit_link = clone.querySelector(".edit_link");
|
edit_url = new URL(edit_url, url_base);
|
||||||
edit_link.href = edit_url
|
let edit_link = clone.querySelector(".edit_link");
|
||||||
|
edit_link.href = edit_url
|
||||||
|
}
|
||||||
|
|
||||||
new_children.push(clone);
|
new_children.push(clone);
|
||||||
}
|
}
|
||||||
@ -149,10 +162,10 @@ async function upload(e) {
|
|||||||
)
|
)
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
refresh_list();
|
refresh_list();
|
||||||
files.value = "";
|
|
||||||
upload_button.disabled = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
files.value = "";
|
||||||
|
upload_button.disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function del(e) {
|
async function del(e) {
|
||||||
|
@ -659,13 +659,13 @@ static void _reply_with_file(socketpool_socket_obj_t *socket, _request *request,
|
|||||||
mp_printf(&_socket_print, "Content-Length: %d\r\n", total_length);
|
mp_printf(&_socket_print, "Content-Length: %d\r\n", total_length);
|
||||||
// TODO: Make this a table to save space.
|
// TODO: Make this a table to save space.
|
||||||
if (_endswith(filename, ".txt") || _endswith(filename, ".py")) {
|
if (_endswith(filename, ".txt") || _endswith(filename, ".py")) {
|
||||||
_send_str(socket, "Content-Type: text/plain\r\n");
|
_send_strs(socket, "Content-Type: text/plain", ";charset=UTF-8\r\n", NULL);
|
||||||
} else if (_endswith(filename, ".js")) {
|
} else if (_endswith(filename, ".js")) {
|
||||||
_send_str(socket, "Content-Type: text/javascript\r\n");
|
_send_strs(socket, "Content-Type: text/javascript", ";charset=UTF-8\r\n", NULL);
|
||||||
} else if (_endswith(filename, ".html")) {
|
} else if (_endswith(filename, ".html")) {
|
||||||
_send_str(socket, "Content-Type: text/html\r\n");
|
_send_strs(socket, "Content-Type: text/html", ";charset=UTF-8\r\n", NULL);
|
||||||
} else if (_endswith(filename, ".json")) {
|
} else if (_endswith(filename, ".json")) {
|
||||||
_send_str(socket, "Content-Type: application/json\r\n");
|
_send_strs(socket, "Content-Type: application/json", ";charset=UTF-8\r\n", NULL);
|
||||||
} else {
|
} else {
|
||||||
_send_str(socket, "Content-Type: application/octet-stream\r\n");
|
_send_str(socket, "Content-Type: application/octet-stream\r\n");
|
||||||
}
|
}
|
||||||
@ -966,6 +966,16 @@ static void _reply_websocket_upgrade(socketpool_socket_obj_t *socket, _request *
|
|||||||
// socket is now closed and "disconnected".
|
// socket is now closed and "disconnected".
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t _hex2nibble(char h) {
|
||||||
|
if ('0' <= h && h <= '9') {
|
||||||
|
return h - '0';
|
||||||
|
} else if ('A' <= h && h <= 'F') {
|
||||||
|
return h - 'A' + 0xa;
|
||||||
|
}
|
||||||
|
// Shouldn't usually use lower case.
|
||||||
|
return h - 'a' + 0xa;
|
||||||
|
}
|
||||||
|
|
||||||
static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
|
static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
|
||||||
if (request->redirect) {
|
if (request->redirect) {
|
||||||
_reply_redirect(socket, request, request->path);
|
_reply_redirect(socket, request, request->path);
|
||||||
@ -983,6 +993,26 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
|
|||||||
_reply_forbidden(socket, request);
|
_reply_forbidden(socket, request);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Decode any percent encoded bytes so that we're left with UTF-8.
|
||||||
|
// We only do this on /fs/ paths and after redirect so that any
|
||||||
|
// path echoing we do stays encoded.
|
||||||
|
size_t o = 0;
|
||||||
|
size_t i = 0;
|
||||||
|
while (i < strlen(request->path)) {
|
||||||
|
if (request->path[i] == '%') {
|
||||||
|
request->path[o] = _hex2nibble(request->path[i + 1]) << 4 | _hex2nibble(request->path[i + 2]);
|
||||||
|
i += 3;
|
||||||
|
} else {
|
||||||
|
if (i != o) {
|
||||||
|
request->path[o] = request->path[i];
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
o += 1;
|
||||||
|
}
|
||||||
|
if (o < i) {
|
||||||
|
request->path[o] = '\0';
|
||||||
|
}
|
||||||
char *path = request->path + 3;
|
char *path = request->path + 3;
|
||||||
size_t pathlen = strlen(path);
|
size_t pathlen = strlen(path);
|
||||||
FATFS *fs = filesystem_circuitpy();
|
FATFS *fs = filesystem_circuitpy();
|
||||||
@ -1350,6 +1380,8 @@ void supervisor_web_workflow_background(void) {
|
|||||||
// Close the active socket if it is no longer connected.
|
// Close the active socket if it is no longer connected.
|
||||||
common_hal_socketpool_socket_close(&active);
|
common_hal_socketpool_socket_close(&active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
websocket_background();
|
||||||
}
|
}
|
||||||
|
|
||||||
void supervisor_stop_web_workflow(void) {
|
void supervisor_stop_web_workflow(void) {
|
||||||
|
@ -26,6 +26,9 @@
|
|||||||
|
|
||||||
#include "supervisor/shared/web_workflow/websocket.h"
|
#include "supervisor/shared/web_workflow/websocket.h"
|
||||||
|
|
||||||
|
#include "py/ringbuf.h"
|
||||||
|
#include "py/runtime.h"
|
||||||
|
#include "shared/runtime/interrupt_char.h"
|
||||||
#include "supervisor/shared/title_bar.h"
|
#include "supervisor/shared/title_bar.h"
|
||||||
|
|
||||||
// TODO: Remove ESP specific stuff. For now, it is useful as we refine the server.
|
// TODO: Remove ESP specific stuff. For now, it is useful as we refine the server.
|
||||||
@ -43,6 +46,11 @@ typedef struct {
|
|||||||
size_t payload_remaining;
|
size_t payload_remaining;
|
||||||
} _websocket;
|
} _websocket;
|
||||||
|
|
||||||
|
// Buffer the incoming serial data in the background so that we can look for the
|
||||||
|
// interrupt character.
|
||||||
|
STATIC ringbuf_t _incoming_ringbuf;
|
||||||
|
STATIC uint8_t _buf[16];
|
||||||
|
|
||||||
static _websocket cp_serial;
|
static _websocket cp_serial;
|
||||||
|
|
||||||
static const char *TAG = "CP websocket";
|
static const char *TAG = "CP websocket";
|
||||||
@ -50,6 +58,8 @@ static const char *TAG = "CP websocket";
|
|||||||
void websocket_init(void) {
|
void websocket_init(void) {
|
||||||
cp_serial.socket.num = -1;
|
cp_serial.socket.num = -1;
|
||||||
cp_serial.socket.connected = false;
|
cp_serial.socket.connected = false;
|
||||||
|
|
||||||
|
ringbuf_init(&_incoming_ringbuf, _buf, sizeof(_buf) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void websocket_handoff(socketpool_socket_obj_t *socket) {
|
void websocket_handoff(socketpool_socket_obj_t *socket) {
|
||||||
@ -193,16 +203,16 @@ bool websocket_available(void) {
|
|||||||
if (!websocket_connected()) {
|
if (!websocket_connected()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_read_next_frame_header();
|
websocket_background();
|
||||||
return cp_serial.payload_remaining > 0 && cp_serial.frame_index >= cp_serial.frame_len;
|
return ringbuf_num_filled(&_incoming_ringbuf) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char websocket_read_char(void) {
|
char websocket_read_char(void) {
|
||||||
uint8_t c;
|
websocket_background();
|
||||||
if (!_read_next_payload_byte(&c)) {
|
if (ringbuf_num_filled(&_incoming_ringbuf) > 0) {
|
||||||
c = -1;
|
return ringbuf_get(&_incoming_ringbuf);
|
||||||
}
|
}
|
||||||
return c;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _websocket_send(_websocket *ws, const char *text, size_t len) {
|
static void _websocket_send(_websocket *ws, const char *text, size_t len) {
|
||||||
@ -246,3 +256,15 @@ static void _websocket_send(_websocket *ws, const char *text, size_t len) {
|
|||||||
void websocket_write(const char *text, size_t len) {
|
void websocket_write(const char *text, size_t len) {
|
||||||
_websocket_send(&cp_serial, text, len);
|
_websocket_send(&cp_serial, text, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void websocket_background(void) {
|
||||||
|
uint8_t c;
|
||||||
|
while (ringbuf_num_empty(&_incoming_ringbuf) > 0 &&
|
||||||
|
_read_next_payload_byte(&c)) {
|
||||||
|
if (c == mp_interrupt_char) {
|
||||||
|
mp_sched_keyboard_interrupt();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ringbuf_put(&_incoming_ringbuf, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -35,4 +35,5 @@ void websocket_handoff(socketpool_socket_obj_t *socket);
|
|||||||
bool websocket_connected(void);
|
bool websocket_connected(void);
|
||||||
bool websocket_available(void);
|
bool websocket_available(void);
|
||||||
char websocket_read_char(void);
|
char websocket_read_char(void);
|
||||||
|
void websocket_background(void);
|
||||||
void websocket_write(const char *text, size_t len);
|
void websocket_write(const char *text, size_t len);
|
||||||
|
4
tests/float/float_format_ftoe.py
Normal file
4
tests/float/float_format_ftoe.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# check a case where rounding was suppressed inappropriately when "f" was
|
||||||
|
# promoted to "e" for large numbers.
|
||||||
|
v = 8.888e32
|
||||||
|
print("%.2f" % v) # '%.2f' format with e32 becomes '%.2e', expect 8.89e+32.
|
1
tests/float/float_format_ftoe.py.exp
Normal file
1
tests/float/float_format_ftoe.py.exp
Normal file
@ -0,0 +1 @@
|
|||||||
|
8.89e+32
|
31
tests/float/float_format_ints.py
Normal file
31
tests/float/float_format_ints.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Test that integers format to exact values.
|
||||||
|
|
||||||
|
for b in [13, 123, 457, 23456]:
|
||||||
|
for r in range(1, 10):
|
||||||
|
e_fmt = "{:." + str(r) + "e}"
|
||||||
|
f_fmt = "{:." + str(r) + "f}"
|
||||||
|
g_fmt = "{:." + str(r) + "g}"
|
||||||
|
for e in range(0, 5):
|
||||||
|
f = b * (10**e)
|
||||||
|
title = str(b) + " x 10^" + str(e)
|
||||||
|
print(title, "with format", e_fmt, "gives", e_fmt.format(f))
|
||||||
|
print(title, "with format", f_fmt, "gives", f_fmt.format(f))
|
||||||
|
print(title, "with format", g_fmt, "gives", g_fmt.format(f))
|
||||||
|
|
||||||
|
# Check that powers of 10 (that fit in float32) format correctly.
|
||||||
|
for i in range(31):
|
||||||
|
# It works to 12 digits on all platforms *except* qemu-arm, where
|
||||||
|
# 10^11 comes out as 10000000820 or something.
|
||||||
|
print("{:.7g}".format(float("1e" + str(i))))
|
||||||
|
|
||||||
|
# 16777215 is 2^24 - 1, the largest integer that can be completely held
|
||||||
|
# in a float32.
|
||||||
|
print("{:f}".format(16777215))
|
||||||
|
# 4294967040 = 16777215 * 128 is the largest integer that is exactly
|
||||||
|
# represented by a float32 and that will also fit within a (signed) int32.
|
||||||
|
# The upper bound of our integer-handling code is actually double this,
|
||||||
|
# but that constant might cause trouble on systems using 32 bit ints.
|
||||||
|
print("{:f}".format(2147483520))
|
||||||
|
# Very large positive integers can be a test for precision and resolution.
|
||||||
|
# This is a weird way to represent 1e38 (largest power of 10 for float32).
|
||||||
|
print("{:.6e}".format(float("9" * 30 + "e8")))
|
15
tests/float/float_format_ints_doubleprec.py
Normal file
15
tests/float/float_format_ints_doubleprec.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Test formatting of very large ints.
|
||||||
|
# Relies on double-precision floats.
|
||||||
|
|
||||||
|
import array
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Challenging way to express 1e200 and 1e100.
|
||||||
|
print("{:.12e}".format(float("9" * 400 + "e-200")))
|
||||||
|
print("{:.12e}".format(float("9" * 400 + "e-300")))
|
||||||
|
|
||||||
|
# These correspond to the binary representation of 1e200 in float64s:
|
||||||
|
v1 = 0x54B249AD2594C37D # 1e100
|
||||||
|
v2 = 0x6974E718D7D7625A # 1e200
|
||||||
|
print("{:.12e}".format(array.array("d", v1.to_bytes(8, sys.byteorder))[0]))
|
||||||
|
print("{:.12e}".format(array.array("d", v2.to_bytes(8, sys.byteorder))[0]))
|
@ -426,6 +426,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
|
|||||||
if upy_float_precision < 64:
|
if upy_float_precision < 64:
|
||||||
skip_tests.add("float/float_divmod.py") # tested by float/float_divmod_relaxed.py instead
|
skip_tests.add("float/float_divmod.py") # tested by float/float_divmod_relaxed.py instead
|
||||||
skip_tests.add("float/float2int_doubleprec_intbig.py")
|
skip_tests.add("float/float2int_doubleprec_intbig.py")
|
||||||
|
skip_tests.add("float/float_format_ints_doubleprec.py")
|
||||||
skip_tests.add("float/float_parse_doubleprec.py")
|
skip_tests.add("float/float_parse_doubleprec.py")
|
||||||
|
|
||||||
if not has_complex:
|
if not has_complex:
|
||||||
|
@ -100,6 +100,7 @@ exclude_tests = (
|
|||||||
"float/float_divmod.py",
|
"float/float_divmod.py",
|
||||||
# requires double precision floating point to work
|
# requires double precision floating point to work
|
||||||
"float/float2int_doubleprec_intbig.py",
|
"float/float2int_doubleprec_intbig.py",
|
||||||
|
"float/float_format_ints_doubleprec.py",
|
||||||
"float/float_parse_doubleprec.py",
|
"float/float_parse_doubleprec.py",
|
||||||
# inline asm FP tests (require Cortex-M4)
|
# inline asm FP tests (require Cortex-M4)
|
||||||
"inlineasm/asmfpaddsub.py",
|
"inlineasm/asmfpaddsub.py",
|
||||||
|
Loading…
Reference in New Issue
Block a user