Fixing code behind commits
This commit is contained in:
Lee Atkinson 2022-08-11 17:58:46 -04:00
commit 6d8e8c71fc
65 changed files with 387 additions and 305 deletions

View File

@ -494,6 +494,45 @@ backticks ``:class:`~adafruit_motor.servo.Servo```. You must also add the refer
"adafruit_motor": ("https://circuitpython.readthedocs.io/projects/motor/en/latest/", None,),
Use ``adafruit_register`` when possible
--------------------------------------------------------------------------------
`Register <https://github.com/adafruit/Adafruit_CircuitPython_Register>`_ is
a foundational library that manages packing and unpacking data from I2C device
registers. There is also `Register SPI <https://github.com/adafruit/Adafruit_CircuitPython_Register_SPI>`_
for SPI devices. When possible, use one of these libraries for unpacking and
packing registers. This ensures the packing code is shared amongst all
registers (even across drivers). Furthermore, it simplifies device definitions
by making them declarative (only data.)
Values with non-consecutive bits in a register or that represent FIFO endpoints
may not map well to existing register classes. In unique cases like these, it is
ok to read and write the register directly.
*Do not* add all registers from a datasheet upfront. Instead, only add the ones
necessary for the functionality the driver exposes. Adding them all will lead to
unnecessary file size and API clutter. See `this video about outside-in design
from @tannewt <https://www.youtube.com/watch?v=3QewiyfBQh8>`_.
I2C Example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
from adafruit_register import i2c_bit
from adafruit_bus_device import i2c_device
class HelloWorldDevice:
"""Device with two bits to control when the words 'hello' and 'world' are lit."""
hello = i2c_bit.RWBit(0x0, 0x0)
"""Bit to indicate if hello is lit."""
world = i2c_bit.RWBit(0x1, 0x0)
"""Bit to indicate if world is lit."""
def __init__(self, i2c, device_address=0x0):
self.i2c_device = i2c_device.I2CDevice(i2c, device_address)
Use BusDevice
--------------------------------------------------------------------------------
@ -668,8 +707,24 @@ when using ``const()``, keep in mind these general guide lines:
- Always use via an import, ex: ``from micropython import const``
- Limit use to global (module level) variables only.
- If user will not need access to variable, prefix name with a leading
underscore, ex: ``_SOME_CONST``.
- Only used when the user will not need access to variable and prefix name with
a leading underscore, ex: ``_SOME_CONST``.
Example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
from adafruit_bus_device import i2c_device
from micropython import const
_DEFAULT_I2C_ADDR = const(0x42)
class Widget:
"""A generic widget."""
def __init__(self, i2c, address=_DEFAULT_I2C_ADDR):
self.i2c_device = i2c_device.I2CDevice(i2c, address)
Libraries Examples
------------------
@ -751,6 +806,16 @@ properties.
| ``sound_level`` | float | non-unit-specific sound level (monotonic but not actual decibels) |
+-----------------------+-----------------------+-------------------------------------------------------------------------+
Driver constant naming
--------------------------------------------------------------------------------
When adding variables for constant values for a driver. Do not include the
device's name in the variable name. For example, in ``adafruit_fancy123.py``,
variables should not start with ``FANCY123_``. Adding this prefix increases RAM
usage and .mpy file size because variable names are preserved. User code should
refer to these constants as ``adafruit_fancy123.HELLO_WORLD`` for clarity.
``adafruit_fancy123.FANCY123_HELLO_WORLD`` would be overly verbose.
Adding native modules
--------------------------------------------------------------------------------

@ -1 +1 @@
Subproject commit f993d5fac69f3a0cfa33988268666c462b72c0ec
Subproject commit 9a8338b3bdaeac9eeb5b74d147107c67db33fdac

View File

@ -104,8 +104,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_PA00,
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -84,8 +84,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_PB14, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -85,8 +85,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_PA23, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -84,7 +84,6 @@ void board_init(void) {
NULL, // &pin_PA17, // brightness pin
NO_BRIGHTNESS_COMMAND,
0.0f, // brightness
false, // auto_brightness
false, // single_byte_bounds
true, // data as commands
true, // auto_refresh

View File

@ -137,8 +137,7 @@ void board_init(void) {
sizeof(display_init_sequence),
NULL, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
false, // auto_refresh

View File

@ -105,8 +105,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_PA01, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -107,8 +107,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_PA01, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -94,8 +94,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_PB31, // Backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -111,8 +111,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_PB31, // Backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -102,8 +102,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_PC05, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -105,7 +105,6 @@ void board_init(void) {
NULL,
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness
false, // auto_brightness
false, // single_byte_bounds
false, // data as commands
true, // auto_refresh

View File

@ -57,7 +57,7 @@
//| pixel_format: PixelFormat=PixelFormat.RGB565,
//| frame_size: FrameSize=FrameSize.QQVGA,
//| jpeg_quality: int=15,
//| double_buffered: bool = True,
//| framebuffer_count: int = 1,
//| grab_mode: GrabMode = GrabMode.WHEN_EMPTY,
//| ) -> None:
//| """

View File

@ -89,8 +89,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO38, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -95,7 +95,7 @@ void board_init(void) {
display->base.type = &displayio_display_type;
// workaround as board_init() is called before reset_port() in main.c
pwmout_reset();
/// pwmout_reset();
common_hal_displayio_display_construct(
display,
@ -118,8 +118,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO45, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
false, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh
@ -128,8 +127,6 @@ void board_init(void) {
false, // SH1107_addressing
50000 // backlight pwm frequency
);
common_hal_never_reset_pin(&pin_GPIO45); // backlight pin
}
bool board_requests_safe_mode(void) {

View File

@ -94,8 +94,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO7, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -118,8 +118,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO45, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
false, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -97,8 +97,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO21, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -80,8 +80,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO45, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -81,8 +81,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO45, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -111,8 +111,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO48, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
false, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -108,8 +108,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO9, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -100,8 +100,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO14, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -112,8 +112,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO45, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
false, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -117,8 +117,7 @@ static void display_init(void) {
sizeof(display_init_sequence),
&pin_GPIO38, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
false, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -117,8 +117,7 @@ static void display_init(void) {
sizeof(display_init_sequence),
&pin_GPIO33, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
false, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -198,8 +198,7 @@ void board_init(void) {
sizeof(display_init_sequence),
NULL, // There is no backlight pin, defined for now.
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -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();
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 = {

View File

@ -336,6 +336,9 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
return WIFI_RADIO_ERROR_NO_AP_FOUND;
}
return self->last_disconnect_reason;
} else {
// We're connected, allow us to retry if we get disconnected.
self->retries_left = self->starting_retries;
}
return WIFI_RADIO_ERROR_NONE;
}

View File

@ -84,8 +84,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_P1_05, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -85,8 +85,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_P1_13, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -85,8 +85,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_P0_20, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -84,8 +84,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_P0_02, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -97,7 +97,6 @@ void board_init(void) {
NULL,
0x81,
1.0f, // brightness
false, // auto_brightness
true, // single_byte_bounds
true, // data as commands
true, // auto_refresh

View File

@ -101,8 +101,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_GPIO12, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
true, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -104,8 +104,7 @@ void board_init(void) {
sizeof(display_init_sequence),
&pin_PB03,
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness (ignored)
false, // auto_brightness
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh

View File

@ -25,6 +25,7 @@
*/
#include "py/mpconfig.h"
#include "py/misc.h"
#if MICROPY_FLOAT_IMPL != MICROPY_FLOAT_IMPL_NONE
#include <assert.h>
@ -96,7 +97,16 @@ static inline int fp_isless1(float x) {
#define fp_iszero(x) (x == 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[] = {
#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;
const FPTYPE *pos_pow = g_pos_pow;
const FPTYPE *neg_pow = g_neg_pow;
int signed_e = 0;
if (fp_iszero(f)) {
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)) {
// We need to figure out what an integer digit will be used
// 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';
}
FPTYPE f_mod = f;
// Build negative exponent
for (e = 0, e1 = FPDECEXP; e1; e1 >>= 1, pos_pow++, neg_pow++) {
if (*neg_pow > f) {
if (*neg_pow > f_mod) {
e += e1;
f *= *pos_pow;
f_mod *= *pos_pow;
}
}
char e_sign_char = '-';
if (fp_isless1(f) && f >= FPROUND_TO_ONE) {
f = FPCONST(1.0);
if (fp_isless1(f_mod) && f_mod >= FPROUND_TO_ONE) {
f_mod = FPCONST(1.0);
if (e == 0) {
e_sign_char = '+';
}
} else if (fp_isless1(f)) {
} else if (fp_isless1(f_mod)) {
e++;
f *= FPCONST(10.0);
f_mod *= FPCONST(10.0);
}
// 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)) {
fmt = 'f';
dec = -1;
*s++ = first_dig;
dec = 0;
if (org_fmt == 'g') {
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;
if (num_digits) {
*s++ = '.';
while (--e && num_digits) {
*s++ = '0';
num_digits--;
}
}
signed_e = 0;
++num_digits;
} else {
// For e & g formats, we'll be printing the exponent, so set the
// sign.
@ -256,22 +254,29 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
prec++;
}
}
signed_e = -e;
}
} else {
// Build positive exponent
for (e = 0, e1 = FPDECEXP; e1; e1 >>= 1, pos_pow++, neg_pow++) {
if (*pos_pow <= f) {
// Build positive exponent.
// We don't modify f at this point to avoid innaccuracies from
// 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;
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
// number too big to fit into the available buffer, then we'll
// 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 {
e_sign = '+';
}
signed_e = e;
}
if (prec < 0) {
// This can happen when the prec is trimmed to prevent buffer overflow
prec = 0;
}
// We now have num.f as a floating point number between >= 1 and < 10
// (or equal to zero), and e contains the absolute value of the power of
// 10 exponent. and (dec + 1) == the number of dgits before the decimal.
// At this point e contains the absolute value of the power of 10 exponent.
// (dec + 1) == the number of dgits before the decimal.
// For e, 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;
}
// Print the digits of the mantissa
for (int i = 0; i < num_digits; ++i, --dec) {
int32_t d = (int32_t)f;
if (d < 0) {
*s++ = '0';
} else {
*s++ = '0' + d;
if (signed_e < 0) {
// The algorithm below treats numbers smaller than 1 by scaling them
// repeatedly by 10 to bring the new digit to the top. Our input number
// was smaller than 1, so scale it up to be 1 <= f < 10.
FPTYPE u_base = FPCONST(1.0);
const FPTYPE *pow_u = g_pos_pow;
for (int m = FPDECEXP; m; m >>= 1, pow_u++) {
if (m & e) {
u_base *= *pow_u;
}
}
if (dec == 0 && prec > 0) {
*s++ = '.';
}
f -= (FPTYPE)d;
f *= FPCONST(10.0);
f *= u_base;
}
// Round
// If we print non-exponential format (i.e. 'f'), but a digit we're going
// to round by (e) is too far away, then there's nothing to round.
if ((org_fmt != 'f' || e <= num_digits) && f >= FPCONST(5.0)) {
int d = 0;
int num_digits_left = num_digits;
for (int digit_index = signed_e; num_digits_left >= 0; --digit_index) {
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;
rs--;
while (1) {
@ -394,7 +437,10 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
}
} else {
// 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;
while (ss > rs) {

View File

@ -54,7 +54,7 @@
//| Most people should not use this class directly. Use a specific display driver instead that will
//| 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`).
//|
//| 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 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 float brightness: Initial display brightness. This value is ignored if auto_brightness is True.
//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism.
//| :param float brightness: Initial display brightness.
//| :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 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_set_column_command, ARG_set_row_command, ARG_write_ram_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_SH1107_addressing, ARG_backlight_pwm_frequency };
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_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_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_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} },
@ -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),
args[ARG_brightness_command].u_int,
brightness,
args[ARG_auto_brightness].u_bool,
args[ARG_single_byte_bounds].u_bool,
args[ARG_data_as_commands].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);
//| brightness: float
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When
//| `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."""
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness."""
//|
STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t 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) {
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);
if (brightness < 0 || brightness > 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_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
//| """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_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_height), MP_ROM_PTR(&displayio_display_height_obj) },

View File

@ -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,
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,
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 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);
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);
void common_hal_displayio_display_set_dither(displayio_display_obj_t *self, bool dither);

View File

@ -48,7 +48,6 @@
//| import time
//| import pulseio
//|
//| board.DISPLAY.auto_brightness = False
//| board.DISPLAY.brightness = 0
//| splash = displayio.Group()
//| board.DISPLAY.show(splash)

View File

@ -173,9 +173,7 @@ MP_PROPERTY_GETSET(framebufferio_framebufferdisplay_auto_refresh_obj,
(mp_obj_t)&framebufferio_framebufferdisplay_set_auto_refresh_obj);
//| brightness: float
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When
//| `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."""
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness."""
//|
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_brightness(mp_obj_t 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) {
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);
if (brightness < 0.0f || brightness > 1.0f) {
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_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
//| """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_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_height), MP_ROM_PTR(&framebufferio_framebufferdisplay_height_obj) },

View File

@ -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);
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);
bool common_hal_framebufferio_framebufferdisplay_set_brightness(framebufferio_framebufferdisplay_obj_t *self, mp_float_t brightness);

View File

@ -42,9 +42,6 @@
//|
//| :param ~microcontroller.Pin pin: Pin connected to the OneWire bus
//|
//| .. note:: The OneWire class is available on `busio` and `bitbangio` in CircuitPython
//| 7.x for backwards compatibility but will be removed in CircuitPython 8.0.0.
//|
//| Read a short series of pulses::
//|
//| import onewireio

View File

@ -48,9 +48,6 @@
//| :param int frequency: Carrier signal frequency in Hertz
//| :param int duty_cycle: 16-bit duty cycle of carrier frequency (0 - 65536)
//|
//| For backwards compatibility, ``pin`` may be a PWMOut object used as the carrier. This
//| compatibility will be removed in CircuitPython 8.0.0.
//|
//| Send a short series of pulses::
//|
//| import array
@ -82,14 +79,6 @@ STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar
const mcu_pin_obj_t *pin = args[ARG_pin].u_obj;
mp_int_t frequency = args[ARG_frequency].u_int;
mp_int_t duty_cycle = args[ARG_duty_cycle].u_int;
if (mp_obj_is_type(args[ARG_pin].u_obj, &pwmio_pwmout_type)) {
pwmio_pwmout_obj_t *pwmout = args[ARG_pin].u_obj;
duty_cycle = common_hal_pwmio_pwmout_get_duty_cycle(pwmout);
frequency = common_hal_pwmio_pwmout_get_frequency(pwmout);
pin = common_hal_pwmio_pwmout_get_pin(pwmout);
// Deinit the pin so we can use it.
common_hal_pwmio_pwmout_deinit(pwmout);
}
validate_obj_is_free_pin(MP_OBJ_FROM_PTR(pin));
pulseio_pulseout_obj_t *self = m_new_obj(pulseio_pulseout_obj_t);
self->base.type = &pulseio_pulseout_type;

View File

@ -34,18 +34,28 @@
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in every byte"""
//|
//| 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
//| """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, 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, ODD_BYTES, QRIO_EVEN_BYTES);
MAKE_ENUM_MAP(qrio_pixel_policy) {
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, ODD_BYTES),
};

View File

@ -33,7 +33,7 @@
extern const mp_obj_type_t qrio_pixel_policy_type;
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;
extern const cp_enum_obj_t qrio_pixel_policy_EVERY_BYTE_obj;

View File

@ -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 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, 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 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->write_ram_command = write_ram_command;
self->brightness_command = brightness_command;
self->auto_brightness = auto_brightness;
self->first_manual_refresh = !auto_refresh;
self->data_as_commands = data_as_commands;
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);
#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);
} else {
self->current_brightness = -1.0;
}
common_hal_displayio_display_set_brightness(self, brightness);
// Set the group after initialization otherwise we may send pixels while we delay in
// 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);
}
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) {
return self->current_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) {
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) {
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;
}
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) {
_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) {
_refresh_display(self);
}
@ -452,7 +422,6 @@ void release_display(displayio_display_obj_t *self) {
void reset_display(displayio_display_obj_t *self) {
common_hal_displayio_display_set_auto_refresh(self, true);
self->auto_brightness = true;
common_hal_displayio_display_show(self, NULL);
}

View File

@ -45,7 +45,6 @@ typedef struct {
pwmio_pwmout_obj_t backlight_pwm;
#endif
};
uint64_t last_backlight_refresh;
uint64_t last_refresh_call;
mp_float_t current_brightness;
uint16_t brightness_command;
@ -57,8 +56,6 @@ typedef struct {
bool auto_refresh;
bool first_manual_refresh;
bool data_as_commands;
bool auto_brightness;
bool updating_backlight;
bool backlight_on_high;
// new quirk for sh1107
bool SH1107_addressing;

View File

@ -113,20 +113,6 @@ uint16_t common_hal_framebufferio_framebufferdisplay_get_height(framebufferio_fr
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) {
if (self->framebuffer_protocol->get_brightness) {
return self->framebuffer_protocol->get_brightness(self->framebuffer);

View File

@ -43,7 +43,6 @@ typedef struct {
mp_obj_t framebuffer;
const struct _framebuffer_p_t *framebuffer_protocol;
mp_buffer_info_t bufinfo;
uint64_t last_backlight_refresh;
uint64_t last_refresh_call;
uint16_t native_frames_per_second;
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);
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_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 int (*framebuffer_get_bytes_per_cell_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_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;
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_FRAMEBUFFERDISPLAY_H

View File

@ -104,6 +104,20 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co
uint8_t *src = bufinfo->buf;
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:
memcpy(framebuffer, src, width * height);
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++) {
framebuffer[i] = src[2 * i];
}
break;
}
quirc_end(self->quirc);

View File

@ -78,6 +78,7 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self, const mcu
uint16_t raw_reading = get_raw_reading(self);
if (raw_reading == TIMEOUT_TICKS) {
common_hal_touchio_touchin_deinit(self);
mp_raise_ValueError(translate("No pulldown on pin; 1Mohm recommended"));
}
self->threshold = raw_reading * 1.05 + 100;

View File

@ -9,7 +9,7 @@
</head>
<body>
<h1><a href="/"><img src="/favicon.ico"/></a>&nbsp;<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>
<table>
<thead><tr><th>Type</th><th>Size</th><th>Path</th><th>Modified</th><th></th></tr></thead>
@ -18,5 +18,5 @@
<hr>
<input type="file" id="files" multiple><button type="submit" id="upload">Upload</button>
<hr>
+🗀&nbsp;<input type="text" id="name"><button type="submit" id="mkdir">Create Directory</button>
+📁&nbsp;<input type="text" id="name"><button type="submit" id="mkdir">Create Directory</button>
</body></html>

View File

@ -6,6 +6,15 @@ var current_path;
var editable = undefined;
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);
if (current_path == "") {
current_path = "/";
@ -46,7 +55,7 @@ async function refresh_list() {
if (window.location.path != "/fs/") {
var clone = template.content.cloneNode(true);
var td = clone.querySelectorAll("td");
td[0].textContent = "🗀";
td[0].textContent = "📁";
var path = clone.querySelector("a");
let parent = new URL("..", "file://" + current_path);
path.href = "#" + parent.pathname;
@ -56,11 +65,13 @@ async function refresh_list() {
new_children.push(clone);
}
data.sort(compareValues);
for (const f of data) {
// Clone the new row and insert it into the table
var clone = template.content.cloneNode(true);
var td = clone.querySelectorAll("td");
var icon = "⬇";
var icon = "⬇";
var file_path = current_path + f.name;
let api_url = new URL("/fs" + file_path, url_base);
let edit_url = "/edit/#" + file_path;
@ -72,12 +83,12 @@ async function refresh_list() {
}
if (f.directory) {
icon = "🗀";
icon = "📁";
} else if(f.name.endsWith(".txt") ||
f.name.endsWith(".py") ||
f.name.endsWith(".js") ||
f.name.endsWith(".json")) {
icon = "🖹";
icon = "📄";
} else if (f.name.endsWith(".html")) {
icon = "🌐";
}
@ -92,9 +103,11 @@ async function refresh_list() {
delete_button.disabled = !editable;
delete_button.onclick = del;
edit_url = new URL(edit_url, url_base);
let edit_link = clone.querySelector(".edit_link");
edit_link.href = edit_url
if (editable && !f.directory) {
edit_url = new URL(edit_url, url_base);
let edit_link = clone.querySelector(".edit_link");
edit_link.href = edit_url
}
new_children.push(clone);
}
@ -149,10 +162,10 @@ async function upload(e) {
)
if (response.ok) {
refresh_list();
files.value = "";
upload_button.disabled = true;
}
}
files.value = "";
upload_button.disabled = true;
}
async function del(e) {

View File

@ -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);
// TODO: Make this a table to save space.
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")) {
_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")) {
_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")) {
_send_str(socket, "Content-Type: application/json\r\n");
_send_strs(socket, "Content-Type: application/json", ";charset=UTF-8\r\n", NULL);
} else {
_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".
}
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) {
if (request->redirect) {
_reply_redirect(socket, request, request->path);
@ -983,6 +993,26 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
_reply_forbidden(socket, request);
}
} 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;
size_t pathlen = strlen(path);
FATFS *fs = filesystem_circuitpy();
@ -1350,6 +1380,8 @@ void supervisor_web_workflow_background(void) {
// Close the active socket if it is no longer connected.
common_hal_socketpool_socket_close(&active);
}
websocket_background();
}
void supervisor_stop_web_workflow(void) {

View File

@ -26,6 +26,9 @@
#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"
// 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;
} _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 const char *TAG = "CP websocket";
@ -50,6 +58,8 @@ static const char *TAG = "CP websocket";
void websocket_init(void) {
cp_serial.socket.num = -1;
cp_serial.socket.connected = false;
ringbuf_init(&_incoming_ringbuf, _buf, sizeof(_buf) - 1);
}
void websocket_handoff(socketpool_socket_obj_t *socket) {
@ -193,16 +203,16 @@ bool websocket_available(void) {
if (!websocket_connected()) {
return false;
}
_read_next_frame_header();
return cp_serial.payload_remaining > 0 && cp_serial.frame_index >= cp_serial.frame_len;
websocket_background();
return ringbuf_num_filled(&_incoming_ringbuf) > 0;
}
char websocket_read_char(void) {
uint8_t c;
if (!_read_next_payload_byte(&c)) {
c = -1;
websocket_background();
if (ringbuf_num_filled(&_incoming_ringbuf) > 0) {
return ringbuf_get(&_incoming_ringbuf);
}
return c;
return -1;
}
static void _websocket_send(_websocket *ws, const char *text, size_t len) {
@ -238,11 +248,20 @@ static void _websocket_send(_websocket *ws, const char *text, size_t len) {
_send_raw(&ws->socket, extended_len, 4);
}
_send_raw(&ws->socket, (const uint8_t *)text, len);
char copy[len];
memcpy(copy, text, len);
copy[len] = '\0';
}
void websocket_write(const char *text, size_t 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);
}
}

View File

@ -35,4 +35,5 @@ void websocket_handoff(socketpool_socket_obj_t *socket);
bool websocket_connected(void);
bool websocket_available(void);
char websocket_read_char(void);
void websocket_background(void);
void websocket_write(const char *text, size_t len);

View 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.

View File

@ -0,0 +1 @@
8.89e+32

View 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")))

View 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]))

View File

@ -426,6 +426,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
if upy_float_precision < 64:
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/float_format_ints_doubleprec.py")
skip_tests.add("float/float_parse_doubleprec.py")
if not has_complex:

View File

@ -96,8 +96,8 @@ def set_boards_to_build(build_all):
if p in IGNORE:
continue
# Boards don't run tests so ignore those as well.
if p.startswith("tests"):
# Boards don't run tests or docs so ignore those as well.
if p.startswith("tests") or p.startswith("docs"):
continue
# As a (nearly) last resort, for some certain files, we compute the settings from the

View File

@ -100,6 +100,7 @@ exclude_tests = (
"float/float_divmod.py",
# requires double precision floating point to work
"float/float2int_doubleprec_intbig.py",
"float/float_format_ints_doubleprec.py",
"float/float_parse_doubleprec.py",
# inline asm FP tests (require Cortex-M4)
"inlineasm/asmfpaddsub.py",