Added doc and translations
This commit is contained in:
parent
12d770b427
commit
8a379830a8
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-10-16 19:50-0500\n"
|
||||
"POT-Creation-Date: 2020-10-26 16:48-0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -477,7 +477,8 @@ msgstr ""
|
||||
msgid "Buffer must be a multiple of 512 bytes"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c
|
||||
#: shared-bindings/bitbangio/I2C.c shared-bindings/busdevice/I2CDevice.c
|
||||
#: shared-bindings/busio/I2C.c
|
||||
msgid "Buffer must be at least length 1"
|
||||
msgstr ""
|
||||
|
||||
@ -1251,6 +1252,11 @@ msgstr ""
|
||||
msgid "No DMA channel found"
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/busdevice/I2CDevice.c
|
||||
#, c-format
|
||||
msgid "No I2C device at address: %x"
|
||||
msgstr ""
|
||||
|
||||
#: ports/esp32s2/common-hal/busio/SPI.c ports/mimxrt10xx/common-hal/busio/SPI.c
|
||||
#: ports/stm/common-hal/busio/SPI.c
|
||||
msgid "No MISO Pin"
|
||||
@ -3181,6 +3187,8 @@ msgstr ""
|
||||
#: ports/esp32s2/boards/espressif_saola_1_wrover/mpconfigboard.h
|
||||
#: ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h
|
||||
#: ports/esp32s2/boards/muselab_nanoesp32_s2/mpconfigboard.h
|
||||
#: ports/esp32s2/boards/targett_module_clip_wroom/mpconfigboard.h
|
||||
#: ports/esp32s2/boards/targett_module_clip_wrover/mpconfigboard.h
|
||||
#: ports/esp32s2/boards/unexpectedmaker_feathers2/mpconfigboard.h
|
||||
#: ports/esp32s2/boards/unexpectedmaker_feathers2_prerelease/mpconfigboard.h
|
||||
msgid "pressing boot button at start up.\n"
|
||||
|
@ -39,10 +39,27 @@
|
||||
|
||||
|
||||
//| class I2CDevice:
|
||||
//| """Two wire serial protocol"""
|
||||
//|
|
||||
//| def __init__(self, i2c, device_address, probe=True) -> None:
|
||||
//|
|
||||
//| """
|
||||
//| Represents a single I2C device and manages locking the bus and the device
|
||||
//| address.
|
||||
//| :param ~busio.I2C i2c: The I2C bus the device is on
|
||||
//| :param int device_address: The 7 bit device address
|
||||
//| :param bool probe: Probe for the device upon object creation, default is true
|
||||
//| .. note:: This class is **NOT** built into CircuitPython. See
|
||||
//| :ref:`here for install instructions <bus_device_installation>`.
|
||||
//| Example:
|
||||
//| .. code-block:: python
|
||||
//| import busio
|
||||
//| from board import *
|
||||
//| from adafruit_bus_device.i2c_device import I2CDevice
|
||||
//| with busio.I2C(SCL, SDA) as i2c:
|
||||
//| device = I2CDevice(i2c, 0x70)
|
||||
//| bytes_read = bytearray(4)
|
||||
//| with device:
|
||||
//| device.readinto(bytes_read)
|
||||
//| # A second transaction
|
||||
//| with device:
|
||||
//| device.write(bytes_read)"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busdevice_i2cdevice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
@ -67,28 +84,30 @@ STATIC mp_obj_t busdevice_i2cdevice_make_new(const mp_obj_type_t *type, size_t n
|
||||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
//| def __enter__(self) -> None:
|
||||
//| """Automatically initializes the hardware on context exit. See FIX
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busdevice_i2cdevice_obj___enter__(mp_obj_t self_in) {
|
||||
common_hal_busdevice_i2cdevice_lock(self_in);
|
||||
return self_in;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(busdevice_i2cdevice___enter___obj, busdevice_i2cdevice_obj___enter__);
|
||||
|
||||
//| def __exit__(self) -> None:
|
||||
//| """Automatically deinitializes the hardware on context exit. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busdevice_i2cdevice_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
common_hal_busdevice_i2cdevice_unlock(args[0]);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busdevice_i2cdevice___exit___obj, 4, 4, busdevice_i2cdevice_obj___exit__);
|
||||
|
||||
//| def readinto(self, buf, *, start=0, end=None):
|
||||
//| """
|
||||
//| Read into ``buf`` from the device. The number of bytes read will be the
|
||||
//| length of ``buf``.
|
||||
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||
//| as if ``buf[start:end]``. This will not cause an allocation like
|
||||
//| ``buf[start:end]`` will so it saves memory.
|
||||
//| :param bytearray buffer: buffer to write into
|
||||
//| :param int start: Index to start writing at
|
||||
//| :param int end: Index to write up to but not include; if None, use ``len(buf)``"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC void readinto(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_WRITE);
|
||||
@ -123,7 +142,19 @@ STATIC mp_obj_t busdevice_i2cdevice_readinto(size_t n_args, const mp_obj_t *pos_
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busdevice_i2cdevice_readinto_obj, 2, busdevice_i2cdevice_readinto);
|
||||
|
||||
|
||||
//| def write(self, buf, *, start=0, end=None):
|
||||
//| """
|
||||
//| Write the bytes from ``buffer`` to the device, then transmit a stop
|
||||
//| bit.
|
||||
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||
//| ``buffer[start:end]`` will so it saves memory.
|
||||
//| :param bytearray buffer: buffer containing the bytes to write
|
||||
//| :param int start: Index to start writing from
|
||||
//| :param int end: Index to read up to but not include; if None, use ``len(buf)``
|
||||
//| """
|
||||
//| ...
|
||||
//|
|
||||
STATIC void write(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_READ);
|
||||
@ -158,32 +189,28 @@ STATIC mp_obj_t busdevice_i2cdevice_write(size_t n_args, const mp_obj_t *pos_arg
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(busdevice_i2cdevice_write_obj, 2, busdevice_i2cdevice_write);
|
||||
|
||||
|
||||
/*STATIC void write_then_readinto(busdevice_i2cdevice_obj_t *self, mp_obj_t out_buffer, mp_obj_t in_buffer,
|
||||
int32_t out_start, mp_int_t out_end, int32_t in_start, mp_int_t in_end) {
|
||||
mp_buffer_info_t out_bufinfo;
|
||||
mp_get_buffer_raise(out_buffer, &out_bufinfo, MP_BUFFER_READ);
|
||||
|
||||
size_t out_length = out_bufinfo.len;
|
||||
normalize_buffer_bounds(&out_start, out_end, &out_length);
|
||||
if (out_length == 0) {
|
||||
mp_raise_ValueError(translate("Buffer must be at least length 1"));
|
||||
}
|
||||
|
||||
mp_buffer_info_t in_bufinfo;
|
||||
mp_get_buffer_raise(in_buffer, &in_bufinfo, MP_BUFFER_WRITE);
|
||||
|
||||
size_t in_length = in_bufinfo.len;
|
||||
normalize_buffer_bounds(&in_start, in_end, &in_length);
|
||||
if (in_length == 0) {
|
||||
mp_raise_ValueError(translate("Buffer must be at least length 1"));
|
||||
}
|
||||
|
||||
uint8_t status = common_hal_busdevice_i2cdevice_write_then_readinto(self, out_buffer, in_buffer, out_length, in_length);
|
||||
if (status != 0) {
|
||||
mp_raise_OSError(status);
|
||||
}
|
||||
}*/
|
||||
|
||||
//| def write_then_readinto(self, out_buffer, in_buffer, *, out_start=0, out_end=None, in_start=0, in_end=None):
|
||||
//| """
|
||||
//| Write the bytes from ``out_buffer`` to the device, then immediately
|
||||
//| reads into ``in_buffer`` from the device. The number of bytes read
|
||||
//| will be the length of ``in_buffer``.
|
||||
//| If ``out_start`` or ``out_end`` is provided, then the output buffer
|
||||
//| will be sliced as if ``out_buffer[out_start:out_end]``. This will
|
||||
//| not cause an allocation like ``buffer[out_start:out_end]`` will so
|
||||
//| it saves memory.
|
||||
//| If ``in_start`` or ``in_end`` is provided, then the input buffer
|
||||
//| will be sliced as if ``in_buffer[in_start:in_end]``. This will not
|
||||
//| cause an allocation like ``in_buffer[in_start:in_end]`` will so
|
||||
//| it saves memory.
|
||||
//| :param bytearray out_buffer: buffer containing the bytes to write
|
||||
//| :param bytearray in_buffer: buffer containing the bytes to read into
|
||||
//| :param int out_start: Index to start writing from
|
||||
//| :param int out_end: Index to read up to but not include; if None, use ``len(out_buffer)``
|
||||
//| :param int in_start: Index to start writing at
|
||||
//| :param int in_end: Index to write up to but not include; if None, use ``len(in_buffer)``
|
||||
//| """
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busdevice_i2cdevice_write_then_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -207,29 +234,17 @@ STATIC mp_obj_t busdevice_i2cdevice_write_then_readinto(size_t n_args, const mp_
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(busdevice_i2cdevice_write_then_readinto_obj, 3, busdevice_i2cdevice_write_then_readinto);
|
||||
|
||||
|
||||
//| def __probe_for_device(self):
|
||||
//| """
|
||||
//| Try to read a byte from an address,
|
||||
//| if you get an OSError it means the device is not there
|
||||
//| or that the device does not support these means of probing
|
||||
//| """
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busdevice_i2cdevice___probe_for_device(mp_obj_t self_in) {
|
||||
busdevice_i2cdevice_obj_t *self = self_in;
|
||||
common_hal_busdevice_i2cdevice___probe_for_device(self);
|
||||
|
||||
/* common_hal_busdevice_i2cdevice_lock(self);
|
||||
|
||||
|
||||
//uint8_t buffer;
|
||||
mp_buffer_info_t bufinfo;
|
||||
//mp_obj_t bufobj = MP_OBJ_FROM_PTR(&buffer)
|
||||
mp_obj_t buffer = mp_obj_new_bytearray_of_zeros(1);
|
||||
|
||||
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_WRITE);
|
||||
|
||||
uint8_t status = common_hal_busdevice_i2cdevice_readinto(self_in, (uint8_t*)bufinfo.buf, 1);
|
||||
if (status != 0) {
|
||||
common_hal_busdevice_i2cdevice_unlock(self_in);
|
||||
mp_raise_ValueError_varg(translate("No I2C device at address: %x"), self->device_address);
|
||||
}
|
||||
|
||||
common_hal_busdevice_i2cdevice_unlock(self);
|
||||
*/
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(busdevice_i2cdevice___probe_for_device_obj, busdevice_i2cdevice___probe_for_device);
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
|
||||
* Copyright (c) 2020 Mark Komus
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
Loading…
x
Reference in New Issue
Block a user