Merge branch 'main' into rp_dp_parallel
This commit is contained in:
commit
e326d7ca80
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -43,8 +43,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
gcc --version
|
gcc --version
|
||||||
python3 --version
|
python3 --version
|
||||||
- name: Translations
|
|
||||||
run: make check-translate
|
|
||||||
- name: New boards check
|
- name: New boards check
|
||||||
run: python3 -u ci_new_boards_check.py
|
run: python3 -u ci_new_boards_check.py
|
||||||
working-directory: tools
|
working-directory: tools
|
||||||
|
8
.github/workflows/pre-commit.yml
vendored
8
.github/workflows/pre-commit.yml
vendored
@ -7,7 +7,6 @@ name: pre-commit
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pre-commit:
|
pre-commit:
|
||||||
@ -16,10 +15,13 @@ jobs:
|
|||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- uses: actions/setup-python@v1
|
- uses: actions/setup-python@v1
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: sudo apt-get update && sudo apt-get install -y gettext
|
run: |
|
||||||
|
sudo apt-add-repository -y -u ppa:pybricks/ppa
|
||||||
|
sudo apt-get install -y black gettext uncrustify
|
||||||
|
pip3 install polib
|
||||||
- name: Populate selected submodules
|
- name: Populate selected submodules
|
||||||
run: git submodule update --init extmod/ulab
|
run: git submodule update --init extmod/ulab
|
||||||
- name: set PY
|
- name: Set PY
|
||||||
run: echo >>$GITHUB_ENV PY="$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')"
|
run: echo >>$GITHUB_ENV PY="$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')"
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
|
@ -11,3 +11,16 @@ repos:
|
|||||||
exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*|ports/esp32s2/esp-idf-config/.*|ports/esp32s2/boards/.*/sdkconfig)'
|
exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*|ports/esp32s2/esp-idf-config/.*|ports/esp32s2/boards/.*/sdkconfig)'
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*)'
|
exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*)'
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: translations
|
||||||
|
name: Translations
|
||||||
|
entry: sh -c "if ! make check-translate; then make translate; fi"
|
||||||
|
types: [c]
|
||||||
|
pass_filenames: false
|
||||||
|
language: system
|
||||||
|
- id: formatting
|
||||||
|
name: Formatting
|
||||||
|
entry: sh -c "git diff --staged --name-only | xargs python3 tools/codeformat.py"
|
||||||
|
types_or: [c, python]
|
||||||
|
language: system
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
|
|
||||||
#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
|
#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
|
||||||
#define SEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000000) / (RESOLUTION))
|
#define SEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000000) / (RESOLUTION))
|
||||||
#define UNITS_TO_SEC(TIME, RESOLUTION) (((TIME) * (RESOLUTION)) / 1000000)
|
#define UNITS_TO_SEC(TIME, RESOLUTION) (((TIME)*(RESOLUTION)) / 1000000)
|
||||||
// 0.625 msecs (625 usecs)
|
// 0.625 msecs (625 usecs)
|
||||||
#define ADV_INTERVAL_UNIT_FLOAT_SECS (0.000625)
|
#define ADV_INTERVAL_UNIT_FLOAT_SECS (0.000625)
|
||||||
// Microseconds is the base unit. The macros above know that.
|
// Microseconds is the base unit. The macros above know that.
|
||||||
@ -63,7 +63,7 @@
|
|||||||
|
|
||||||
// TODO make this settable from Python.
|
// TODO make this settable from Python.
|
||||||
#define DEFAULT_TX_POWER 0 // 0 dBm
|
#define DEFAULT_TX_POWER 0 // 0 dBm
|
||||||
#define MAX_ANONYMOUS_ADV_TIMEOUT_SECS (60*15)
|
#define MAX_ANONYMOUS_ADV_TIMEOUT_SECS (60 * 15)
|
||||||
#define MAX_LIMITED_DISCOVERABLE_ADV_TIMEOUT_SECS (180)
|
#define MAX_LIMITED_DISCOVERABLE_ADV_TIMEOUT_SECS (180)
|
||||||
|
|
||||||
#define BLE_MIN_CONN_INTERVAL MSEC_TO_UNITS(15, UNIT_0_625_MS)
|
#define BLE_MIN_CONN_INTERVAL MSEC_TO_UNITS(15, UNIT_0_625_MS)
|
||||||
@ -289,7 +289,7 @@ STATIC void bleio_adapter_hci_init(bleio_adapter_obj_t *self) {
|
|||||||
|
|
||||||
// Get version information.
|
// Get version information.
|
||||||
if (hci_read_local_version(&self->hci_version, &self->hci_revision, &self->lmp_version,
|
if (hci_read_local_version(&self->hci_version, &self->hci_revision, &self->lmp_version,
|
||||||
&self->manufacturer, &self->lmp_subversion) != HCI_OK) {
|
&self->manufacturer, &self->lmp_subversion) != HCI_OK) {
|
||||||
mp_raise_bleio_BluetoothError(translate("Could not read HCI version"));
|
mp_raise_bleio_BluetoothError(translate("Could not read HCI version"));
|
||||||
}
|
}
|
||||||
// Get supported features.
|
// Get supported features.
|
||||||
@ -414,11 +414,11 @@ bool common_hal_bleio_adapter_set_address(bleio_adapter_obj_t *self, bleio_addre
|
|||||||
return hci_le_set_random_address(bufinfo.buf) == HCI_OK;
|
return hci_le_set_random_address(bufinfo.buf) == HCI_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_str_t* common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self) {
|
mp_obj_str_t *common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self) {
|
||||||
return self->name;
|
return self->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char* name) {
|
void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char *name) {
|
||||||
self->name = mp_obj_new_str(name, strlen(name));
|
self->name = mp_obj_new_str(name, strlen(name));
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
mp_get_buffer_raise(self->name, &bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(self->name, &bufinfo, MP_BUFFER_READ);
|
||||||
@ -459,7 +459,7 @@ void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char* na
|
|||||||
// return true;
|
// return true;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t* prefixes, size_t prefix_length, bool extended, mp_int_t buffer_size, mp_float_t timeout, mp_float_t interval, mp_float_t window, mp_int_t minimum_rssi, bool active) {
|
mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t *prefixes, size_t prefix_length, bool extended, mp_int_t buffer_size, mp_float_t timeout, mp_float_t interval, mp_float_t window, mp_int_t minimum_rssi, bool active) {
|
||||||
// TODO
|
// TODO
|
||||||
mp_raise_NotImplementedError(NULL);
|
mp_raise_NotImplementedError(NULL);
|
||||||
check_enabled(self);
|
check_enabled(self);
|
||||||
@ -704,7 +704,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
|
|||||||
|
|
||||||
uint8_t handle[1] = { 0 };
|
uint8_t handle[1] = { 0 };
|
||||||
uint16_t duration_10msec[1] = { timeout * 100 };
|
uint16_t duration_10msec[1] = { timeout * 100 };
|
||||||
uint8_t max_ext_adv_evts[1] = { 0 };
|
uint8_t max_ext_adv_evts[1] = { 0 };
|
||||||
hci_check_error(
|
hci_check_error(
|
||||||
hci_le_set_extended_advertising_enable(
|
hci_le_set_extended_advertising_enable(
|
||||||
BT_HCI_LE_ADV_ENABLE,
|
BT_HCI_LE_ADV_ENABLE,
|
||||||
@ -789,11 +789,11 @@ void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool
|
|||||||
} else {
|
} else {
|
||||||
if (timeout > MAX_LIMITED_DISCOVERABLE_ADV_TIMEOUT_SECS) {
|
if (timeout > MAX_LIMITED_DISCOVERABLE_ADV_TIMEOUT_SECS) {
|
||||||
mp_raise_bleio_BluetoothError(translate("Timeout is too long: Maximum timeout length is %d seconds"),
|
mp_raise_bleio_BluetoothError(translate("Timeout is too long: Maximum timeout length is %d seconds"),
|
||||||
MAX_LIMITED_DISCOVERABLE_ADV_TIMEOUT_SECS);
|
MAX_LIMITED_DISCOVERABLE_ADV_TIMEOUT_SECS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t result =_common_hal_bleio_adapter_start_advertising(
|
const uint32_t result = _common_hal_bleio_adapter_start_advertising(
|
||||||
self, connectable, anonymous, timeout, interval,
|
self, connectable, anonymous, timeout, interval,
|
||||||
advertising_data_bufinfo->buf,
|
advertising_data_bufinfo->buf,
|
||||||
advertising_data_bufinfo->len,
|
advertising_data_bufinfo->len,
|
||||||
@ -820,11 +820,11 @@ void common_hal_bleio_adapter_stop_advertising(bleio_adapter_obj_t *self) {
|
|||||||
hci_check_error(result);
|
hci_check_error(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO startup CircuitPython advertising again.
|
// TODO startup CircuitPython advertising again.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that something stopped advertising, such as a connection happening.
|
// Note that something stopped advertising, such as a connection happening.
|
||||||
//Don't ask the adapter to stop.
|
// Don't ask the adapter to stop.
|
||||||
void bleio_adapter_advertising_was_stopped(bleio_adapter_obj_t *self) {
|
void bleio_adapter_advertising_was_stopped(bleio_adapter_obj_t *self) {
|
||||||
self->now_advertising = false;
|
self->now_advertising = false;
|
||||||
self->extended_advertising = false;
|
self->extended_advertising = false;
|
||||||
@ -876,14 +876,14 @@ void common_hal_bleio_adapter_erase_bonding(bleio_adapter_obj_t *self) {
|
|||||||
mp_raise_NotImplementedError(NULL);
|
mp_raise_NotImplementedError(NULL);
|
||||||
check_enabled(self);
|
check_enabled(self);
|
||||||
|
|
||||||
//FIX bonding_erase_storage();
|
// FIX bonding_erase_storage();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t bleio_adapter_add_attribute(bleio_adapter_obj_t *adapter, mp_obj_t *attribute) {
|
uint16_t bleio_adapter_add_attribute(bleio_adapter_obj_t *adapter, mp_obj_t *attribute) {
|
||||||
check_enabled(adapter);
|
check_enabled(adapter);
|
||||||
|
|
||||||
// The handle is the index of this attribute in the attributes list.
|
// The handle is the index of this attribute in the attributes list.
|
||||||
uint16_t handle = (uint16_t) adapter->attributes->len;
|
uint16_t handle = (uint16_t)adapter->attributes->len;
|
||||||
mp_obj_list_append(adapter->attributes, attribute);
|
mp_obj_list_append(adapter->attributes, attribute);
|
||||||
|
|
||||||
if (MP_OBJ_IS_TYPE(attribute, &bleio_service_type)) {
|
if (MP_OBJ_IS_TYPE(attribute, &bleio_service_type)) {
|
||||||
@ -896,7 +896,7 @@ uint16_t bleio_adapter_add_attribute(bleio_adapter_obj_t *adapter, mp_obj_t *att
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t* bleio_adapter_get_attribute(bleio_adapter_obj_t *adapter, uint16_t handle) {
|
mp_obj_t *bleio_adapter_get_attribute(bleio_adapter_obj_t *adapter, uint16_t handle) {
|
||||||
check_enabled(adapter);
|
check_enabled(adapter);
|
||||||
|
|
||||||
if (handle == 0 || handle >= adapter->attributes->len) {
|
if (handle == 0 || handle >= adapter->attributes->len) {
|
||||||
@ -912,12 +912,12 @@ uint16_t bleio_adapter_max_attribute_handle(bleio_adapter_obj_t *adapter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void bleio_adapter_gc_collect(bleio_adapter_obj_t* adapter) {
|
void bleio_adapter_gc_collect(bleio_adapter_obj_t *adapter) {
|
||||||
gc_collect_root((void**)adapter, sizeof(bleio_adapter_obj_t) / sizeof(size_t));
|
gc_collect_root((void **)adapter, sizeof(bleio_adapter_obj_t) / sizeof(size_t));
|
||||||
gc_collect_root((void**)bleio_connections, sizeof(bleio_connections) / sizeof(size_t));
|
gc_collect_root((void **)bleio_connections, sizeof(bleio_connections) / sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void bleio_adapter_reset(bleio_adapter_obj_t* adapter) {
|
void bleio_adapter_reset(bleio_adapter_obj_t *adapter) {
|
||||||
|
|
||||||
if (!common_hal_bleio_adapter_get_enabled(adapter)) {
|
if (!common_hal_bleio_adapter_get_enabled(adapter)) {
|
||||||
return;
|
return;
|
||||||
@ -939,7 +939,7 @@ void bleio_adapter_reset(bleio_adapter_obj_t* adapter) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bleio_adapter_background(bleio_adapter_obj_t* adapter) {
|
void bleio_adapter_background(bleio_adapter_obj_t *adapter) {
|
||||||
if (!common_hal_bleio_adapter_get_enabled(adapter)) {
|
if (!common_hal_bleio_adapter_get_enabled(adapter)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ typedef struct _bleio_adapter_obj_t {
|
|||||||
bleio_scanresults_obj_t *scan_results;
|
bleio_scanresults_obj_t *scan_results;
|
||||||
mp_obj_t name;
|
mp_obj_t name;
|
||||||
mp_obj_tuple_t *connection_objs;
|
mp_obj_tuple_t *connection_objs;
|
||||||
busio_uart_obj_t* hci_uart;
|
busio_uart_obj_t *hci_uart;
|
||||||
digitalio_digitalinout_obj_t *rts_digitalinout;
|
digitalio_digitalinout_obj_t *rts_digitalinout;
|
||||||
digitalio_digitalinout_obj_t *cts_digitalinout;
|
digitalio_digitalinout_obj_t *cts_digitalinout;
|
||||||
bool allocated; // True when in use.
|
bool allocated; // True when in use.
|
||||||
@ -72,7 +72,7 @@ typedef struct _bleio_adapter_obj_t {
|
|||||||
// Generic services characteristics.
|
// Generic services characteristics.
|
||||||
bleio_characteristic_obj_t *device_name_characteristic;
|
bleio_characteristic_obj_t *device_name_characteristic;
|
||||||
bleio_characteristic_obj_t *appearance_characteristic;
|
bleio_characteristic_obj_t *appearance_characteristic;
|
||||||
bleio_characteristic_obj_t * service_changed_characteristic;
|
bleio_characteristic_obj_t *service_changed_characteristic;
|
||||||
|
|
||||||
uint16_t max_acl_buffer_len;
|
uint16_t max_acl_buffer_len;
|
||||||
uint16_t max_acl_num_buffers;
|
uint16_t max_acl_num_buffers;
|
||||||
@ -90,10 +90,10 @@ typedef struct _bleio_adapter_obj_t {
|
|||||||
|
|
||||||
uint16_t bleio_adapter_add_attribute(bleio_adapter_obj_t *adapter, mp_obj_t *attribute);
|
uint16_t bleio_adapter_add_attribute(bleio_adapter_obj_t *adapter, mp_obj_t *attribute);
|
||||||
void bleio_adapter_advertising_was_stopped(bleio_adapter_obj_t *self);
|
void bleio_adapter_advertising_was_stopped(bleio_adapter_obj_t *self);
|
||||||
mp_obj_t* bleio_adapter_get_attribute(bleio_adapter_obj_t *adapter, uint16_t handle);
|
mp_obj_t *bleio_adapter_get_attribute(bleio_adapter_obj_t *adapter, uint16_t handle);
|
||||||
uint16_t bleio_adapter_max_attribute_handle(bleio_adapter_obj_t *adapter);
|
uint16_t bleio_adapter_max_attribute_handle(bleio_adapter_obj_t *adapter);
|
||||||
void bleio_adapter_background(bleio_adapter_obj_t* adapter);
|
void bleio_adapter_background(bleio_adapter_obj_t *adapter);
|
||||||
void bleio_adapter_gc_collect(bleio_adapter_obj_t* adapter);
|
void bleio_adapter_gc_collect(bleio_adapter_obj_t *adapter);
|
||||||
void bleio_adapter_reset(bleio_adapter_obj_t* adapter);
|
void bleio_adapter_reset(bleio_adapter_obj_t *adapter);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ADAPTER_H
|
#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ADAPTER_H
|
||||||
|
@ -78,16 +78,16 @@ bleio_service_obj_t *common_hal_bleio_characteristic_get_service(bleio_character
|
|||||||
return self->service;
|
return self->service;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self, uint8_t* buf, size_t len) {
|
size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self, uint8_t *buf, size_t len) {
|
||||||
// Do GATT operations only if this characteristic has been added to a registered service.
|
// Do GATT operations only if this characteristic has been added to a registered service.
|
||||||
if (self->handle != BLE_GATT_HANDLE_INVALID) {
|
if (self->handle != BLE_GATT_HANDLE_INVALID) {
|
||||||
//FIX uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
|
// FIX uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
|
||||||
if (common_hal_bleio_service_get_is_remote(self->service)) {
|
if (common_hal_bleio_service_get_is_remote(self->service)) {
|
||||||
//FIX read remote chars
|
// FIX read remote chars
|
||||||
//uint8_t rsp[MAX(len, 512)];
|
// uint8_t rsp[MAX(len, 512)];
|
||||||
//FIX improve att_read_req to write into our requested buffer.
|
// FIX improve att_read_req to write into our requested buffer.
|
||||||
// return att_read_req(conn_handle, self->handle, rsp);
|
// return att_read_req(conn_handle, self->handle, rsp);
|
||||||
return 0; //FIX
|
return 0; // FIX
|
||||||
} else {
|
} else {
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
if (!mp_get_buffer(self->value, &bufinfo, MP_BUFFER_READ)) {
|
if (!mp_get_buffer(self->value, &bufinfo, MP_BUFFER_READ)) {
|
||||||
@ -113,13 +113,13 @@ void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self,
|
|||||||
// Do GATT operations only if this characteristic has been added to a registered service.
|
// Do GATT operations only if this characteristic has been added to a registered service.
|
||||||
if (self->handle != BLE_GATT_HANDLE_INVALID) {
|
if (self->handle != BLE_GATT_HANDLE_INVALID) {
|
||||||
if (common_hal_bleio_service_get_is_remote(self->service)) {
|
if (common_hal_bleio_service_get_is_remote(self->service)) {
|
||||||
//FIX uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
|
// FIX uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
|
||||||
if (self->props & CHAR_PROP_WRITE) {
|
if (self->props & CHAR_PROP_WRITE) {
|
||||||
//FIX writing remote chars
|
// FIX writing remote chars
|
||||||
//uint8_t rsp[sizeof(bt_att_error_rsp)];
|
// uint8_t rsp[sizeof(bt_att_error_rsp)];
|
||||||
//att_write_req(conn_handle, self->handle, bufinfo->buf, bufinfo->len, rsp);
|
// att_write_req(conn_handle, self->handle, bufinfo->buf, bufinfo->len, rsp);
|
||||||
} else if (self->props & CHAR_PROP_WRITE_NO_RESPONSE) {
|
} else if (self->props & CHAR_PROP_WRITE_NO_RESPONSE) {
|
||||||
//att_write_cmd(conn_handle, self->handle, bufinfo->buff, bufinfo->len);
|
// att_write_cmd(conn_handle, self->handle, bufinfo->buff, bufinfo->len);
|
||||||
} else {
|
} else {
|
||||||
mp_raise_bleio_BluetoothError(translate("Characteristic not writable"));
|
mp_raise_bleio_BluetoothError(translate("Characteristic not writable"));
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ void common_hal_bleio_characteristic_add_descriptor(bleio_characteristic_obj_t *
|
|||||||
self->service->end_handle = descriptor->handle;
|
self->service->end_handle = descriptor->handle;
|
||||||
|
|
||||||
mp_obj_list_append(MP_OBJ_FROM_PTR(self->descriptor_list),
|
mp_obj_list_append(MP_OBJ_FROM_PTR(self->descriptor_list),
|
||||||
MP_OBJ_FROM_PTR(descriptor));
|
MP_OBJ_FROM_PTR(descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate) {
|
void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate) {
|
||||||
@ -191,8 +191,8 @@ void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self,
|
|||||||
(notify ? CCCD_NOTIFY : 0) |
|
(notify ? CCCD_NOTIFY : 0) |
|
||||||
(indicate ? CCCD_INDICATE : 0);
|
(indicate ? CCCD_INDICATE : 0);
|
||||||
|
|
||||||
//FIX do remote
|
// FIX do remote
|
||||||
(void) cccd_value;
|
(void)cccd_value;
|
||||||
// uint8_t rsp[sizeof(bt_att_error_rsp)];
|
// uint8_t rsp[sizeof(bt_att_error_rsp)];
|
||||||
// if (att_write_req(conn_handle, self->cccd->handle, &cccd_value, sizeof(cccd_value)) == 0) {
|
// if (att_write_req(conn_handle, self->cccd->handle, &cccd_value, sizeof(cccd_value)) == 0) {
|
||||||
// mp_raise_bleio_BluetoothError(translate("Could not write CCCD"));
|
// mp_raise_bleio_BluetoothError(translate("Could not write CCCD"));
|
||||||
|
@ -47,9 +47,9 @@ void bleio_characteristic_buffer_update(bleio_characteristic_buffer_obj_t *self,
|
|||||||
|
|
||||||
// Assumes that timeout and buffer_size have been validated before call.
|
// Assumes that timeout and buffer_size have been validated before call.
|
||||||
void common_hal_bleio_characteristic_buffer_construct(bleio_characteristic_buffer_obj_t *self,
|
void common_hal_bleio_characteristic_buffer_construct(bleio_characteristic_buffer_obj_t *self,
|
||||||
bleio_characteristic_obj_t *characteristic,
|
bleio_characteristic_obj_t *characteristic,
|
||||||
mp_float_t timeout,
|
mp_float_t timeout,
|
||||||
size_t buffer_size) {
|
size_t buffer_size) {
|
||||||
|
|
||||||
self->characteristic = characteristic;
|
self->characteristic = characteristic;
|
||||||
self->timeout_ms = timeout * 1000;
|
self->timeout_ms = timeout * 1000;
|
||||||
@ -64,10 +64,10 @@ uint32_t common_hal_bleio_characteristic_buffer_read(bleio_characteristic_buffer
|
|||||||
uint64_t start_ticks = supervisor_ticks_ms64();
|
uint64_t start_ticks = supervisor_ticks_ms64();
|
||||||
|
|
||||||
// Wait for all bytes received or timeout
|
// Wait for all bytes received or timeout
|
||||||
while ( (ringbuf_num_filled(&self->ringbuf) < len) && (supervisor_ticks_ms64() - start_ticks < self->timeout_ms) ) {
|
while ((ringbuf_num_filled(&self->ringbuf) < len) && (supervisor_ticks_ms64() - start_ticks < self->timeout_ms)) {
|
||||||
RUN_BACKGROUND_TASKS;
|
RUN_BACKGROUND_TASKS;
|
||||||
// Allow user to break out of a timeout with a KeyboardInterrupt.
|
// Allow user to break out of a timeout with a KeyboardInterrupt.
|
||||||
if ( mp_hal_is_interrupted() ) {
|
if (mp_hal_is_interrupted()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,8 +97,8 @@ void common_hal_bleio_characteristic_buffer_deinit(bleio_characteristic_buffer_o
|
|||||||
|
|
||||||
bool common_hal_bleio_characteristic_buffer_connected(bleio_characteristic_buffer_obj_t *self) {
|
bool common_hal_bleio_characteristic_buffer_connected(bleio_characteristic_buffer_obj_t *self) {
|
||||||
return self->characteristic != NULL &&
|
return self->characteristic != NULL &&
|
||||||
self->characteristic->service != NULL &&
|
self->characteristic->service != NULL &&
|
||||||
(!self->characteristic->service->is_remote ||
|
(!self->characteristic->service->is_remote ||
|
||||||
(self->characteristic->service->connection != MP_OBJ_NULL &&
|
(self->characteristic->service->connection != MP_OBJ_NULL &&
|
||||||
common_hal_bleio_connection_get_connected(self->characteristic->service->connection)));
|
common_hal_bleio_connection_get_connected(self->characteristic->service->connection)));
|
||||||
}
|
}
|
||||||
|
@ -73,8 +73,8 @@
|
|||||||
static volatile bool m_discovery_in_process;
|
static volatile bool m_discovery_in_process;
|
||||||
static volatile bool m_discovery_successful;
|
static volatile bool m_discovery_successful;
|
||||||
|
|
||||||
//FIX static bleio_service_obj_t *m_char_discovery_service;
|
// FIX static bleio_service_obj_t *m_char_discovery_service;
|
||||||
//FIX static bleio_characteristic_obj_t *m_desc_discovery_characteristic;
|
// FIX static bleio_characteristic_obj_t *m_desc_discovery_characteristic;
|
||||||
|
|
||||||
// bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
|
// bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
|
||||||
// bleio_connection_internal_t *self = (bleio_connection_internal_t*)self_in;
|
// bleio_connection_internal_t *self = (bleio_connection_internal_t*)self_in;
|
||||||
@ -326,7 +326,7 @@ void bleio_connection_clear(bleio_connection_internal_t *self) {
|
|||||||
self->conn_handle = BLE_CONN_HANDLE_INVALID;
|
self->conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||||
self->pair_status = PAIR_NOT_PAIRED;
|
self->pair_status = PAIR_NOT_PAIRED;
|
||||||
self->is_central = false;
|
self->is_central = false;
|
||||||
//FIX bonding_clear_keys(&self->bonding_keys);
|
// FIX bonding_clear_keys(&self->bonding_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_bleio_connection_get_paired(bleio_connection_obj_t *self) {
|
bool common_hal_bleio_connection_get_paired(bleio_connection_obj_t *self) {
|
||||||
@ -350,7 +350,7 @@ void common_hal_bleio_connection_disconnect(bleio_connection_internal_t *self) {
|
|||||||
void common_hal_bleio_connection_pair(bleio_connection_internal_t *self, bool bond) {
|
void common_hal_bleio_connection_pair(bleio_connection_internal_t *self, bool bond) {
|
||||||
self->pair_status = PAIR_WAITING;
|
self->pair_status = PAIR_WAITING;
|
||||||
|
|
||||||
//FIX check_nrf_error(sd_ble_gap_authenticate(self->conn_handle, &pairing_sec_params));
|
// FIX check_nrf_error(sd_ble_gap_authenticate(self->conn_handle, &pairing_sec_params));
|
||||||
|
|
||||||
while (self->pair_status == PAIR_WAITING && !mp_hal_is_interrupted()) {
|
while (self->pair_status == PAIR_WAITING && !mp_hal_is_interrupted()) {
|
||||||
RUN_BACKGROUND_TASKS;
|
RUN_BACKGROUND_TASKS;
|
||||||
@ -358,14 +358,14 @@ void common_hal_bleio_connection_pair(bleio_connection_internal_t *self, bool bo
|
|||||||
if (mp_hal_is_interrupted()) {
|
if (mp_hal_is_interrupted()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//FIX check_sec_status(self->sec_status);
|
// FIX check_sec_status(self->sec_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_float_t common_hal_bleio_connection_get_connection_interval(bleio_connection_internal_t *self) {
|
mp_float_t common_hal_bleio_connection_get_connection_interval(bleio_connection_internal_t *self) {
|
||||||
while (self->conn_params_updating && !mp_hal_is_interrupted()) {
|
while (self->conn_params_updating && !mp_hal_is_interrupted()) {
|
||||||
RUN_BACKGROUND_TASKS;
|
RUN_BACKGROUND_TASKS;
|
||||||
}
|
}
|
||||||
//FIX return 1.25f * self->conn_params.min_conn_interval;
|
// FIX return 1.25f * self->conn_params.min_conn_interval;
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -729,14 +729,14 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
mp_obj_tuple_t *common_hal_bleio_connection_discover_remote_services(bleio_connection_obj_t *self, mp_obj_t service_uuids_whitelist) {
|
mp_obj_tuple_t *common_hal_bleio_connection_discover_remote_services(bleio_connection_obj_t *self, mp_obj_t service_uuids_whitelist) {
|
||||||
//FIX discover_remote_services(self->connection, service_uuids_whitelist);
|
// FIX discover_remote_services(self->connection, service_uuids_whitelist);
|
||||||
bleio_connection_ensure_connected(self);
|
bleio_connection_ensure_connected(self);
|
||||||
// Convert to a tuple and then clear the list so the callee will take ownership.
|
// Convert to a tuple and then clear the list so the callee will take ownership.
|
||||||
mp_obj_tuple_t *services_tuple =
|
mp_obj_tuple_t *services_tuple =
|
||||||
mp_obj_new_tuple(self->connection->remote_service_list->len,
|
mp_obj_new_tuple(self->connection->remote_service_list->len,
|
||||||
self->connection->remote_service_list->items);
|
self->connection->remote_service_list->items);
|
||||||
mp_obj_list_clear(MP_OBJ_FROM_PTR(self->connection->remote_service_list));
|
mp_obj_list_clear(MP_OBJ_FROM_PTR(self->connection->remote_service_list));
|
||||||
return services_tuple;
|
return services_tuple;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self) {
|
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self) {
|
||||||
@ -746,7 +746,7 @@ uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self) {
|
|||||||
return self->connection->conn_handle;
|
return self->connection->conn_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t* internal) {
|
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *internal) {
|
||||||
if (internal->connection_obj != mp_const_none) {
|
if (internal->connection_obj != mp_const_none) {
|
||||||
return internal->connection_obj;
|
return internal->connection_obj;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ typedef struct {
|
|||||||
volatile pair_status_t pair_status;
|
volatile pair_status_t pair_status;
|
||||||
uint8_t sec_status; // Internal security status.
|
uint8_t sec_status; // Internal security status.
|
||||||
mp_obj_t connection_obj;
|
mp_obj_t connection_obj;
|
||||||
//REMOVE ble_gap_conn_params_t conn_params;
|
// REMOVE ble_gap_conn_params_t conn_params;
|
||||||
volatile bool conn_params_updating;
|
volatile bool conn_params_updating;
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
// Request that CCCD values for this connection be saved, using sys_attr values.
|
// Request that CCCD values for this connection be saved, using sys_attr values.
|
||||||
@ -70,20 +70,20 @@ typedef struct {
|
|||||||
// Time of setting do_bond_ccds: we delay a bit to consolidate multiple CCCD changes
|
// Time of setting do_bond_ccds: we delay a bit to consolidate multiple CCCD changes
|
||||||
// into one write. Time is currently in ticks_ms.
|
// into one write. Time is currently in ticks_ms.
|
||||||
uint64_t do_bond_cccds_request_time;
|
uint64_t do_bond_cccds_request_time;
|
||||||
//FIX from att.c
|
// FIX from att.c
|
||||||
uint8_t role;
|
uint8_t role;
|
||||||
bt_addr_le_t addr;
|
bt_addr_le_t addr;
|
||||||
} bleio_connection_internal_t;
|
} bleio_connection_internal_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
bleio_connection_internal_t* connection;
|
bleio_connection_internal_t *connection;
|
||||||
// The HCI disconnect reason.
|
// The HCI disconnect reason.
|
||||||
uint8_t disconnect_reason;
|
uint8_t disconnect_reason;
|
||||||
} bleio_connection_obj_t;
|
} bleio_connection_obj_t;
|
||||||
|
|
||||||
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
|
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
|
||||||
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t* connection);
|
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *connection);
|
||||||
bleio_connection_internal_t *bleio_conn_handle_to_connection(uint16_t conn_handle);
|
bleio_connection_internal_t *bleio_conn_handle_to_connection(uint16_t conn_handle);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_CONNECTION_H
|
#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_CONNECTION_H
|
||||||
|
@ -44,7 +44,7 @@ void common_hal_bleio_descriptor_construct(bleio_descriptor_obj_t *self, bleio_c
|
|||||||
const mp_int_t max_length_max = fixed_length ? BLE_GATTS_FIX_ATTR_LEN_MAX : BLE_GATTS_VAR_ATTR_LEN_MAX;
|
const mp_int_t max_length_max = fixed_length ? BLE_GATTS_FIX_ATTR_LEN_MAX : BLE_GATTS_VAR_ATTR_LEN_MAX;
|
||||||
if (max_length < 0 || max_length > max_length_max) {
|
if (max_length < 0 || max_length > max_length_max) {
|
||||||
mp_raise_ValueError_varg(translate("max_length must be 0-%d when fixed_length is %s"),
|
mp_raise_ValueError_varg(translate("max_length must be 0-%d when fixed_length is %s"),
|
||||||
max_length_max, fixed_length ? "True" : "False");
|
max_length_max, fixed_length ? "True" : "False");
|
||||||
}
|
}
|
||||||
self->max_length = max_length;
|
self->max_length = max_length;
|
||||||
self->fixed_length = fixed_length;
|
self->fixed_length = fixed_length;
|
||||||
@ -60,14 +60,14 @@ bleio_characteristic_obj_t *common_hal_bleio_descriptor_get_characteristic(bleio
|
|||||||
return self->characteristic;
|
return self->characteristic;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t common_hal_bleio_descriptor_get_value(bleio_descriptor_obj_t *self, uint8_t* buf, size_t len) {
|
size_t common_hal_bleio_descriptor_get_value(bleio_descriptor_obj_t *self, uint8_t *buf, size_t len) {
|
||||||
// Do GATT operations only if this descriptor has been registered
|
// Do GATT operations only if this descriptor has been registered
|
||||||
if (self->handle != BLE_GATT_HANDLE_INVALID) {
|
if (self->handle != BLE_GATT_HANDLE_INVALID) {
|
||||||
if (common_hal_bleio_service_get_is_remote(self->characteristic->service)) {
|
if (common_hal_bleio_service_get_is_remote(self->characteristic->service)) {
|
||||||
//uint16_t conn_handle = bleio_connection_get_conn_handle(self->characteristic->service->connection);
|
// uint16_t conn_handle = bleio_connection_get_conn_handle(self->characteristic->service->connection);
|
||||||
//FIX have att_read_req fill in a buffer
|
// FIX have att_read_req fill in a buffer
|
||||||
//uint8_t rsp[MAX(len, 512)];
|
// uint8_t rsp[MAX(len, 512)];
|
||||||
//return att_read_req(conn_handle, self->handle, rsp, len);
|
// return att_read_req(conn_handle, self->handle, rsp, len);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
@ -96,7 +96,7 @@ void common_hal_bleio_descriptor_set_value(bleio_descriptor_obj_t *self, mp_buff
|
|||||||
// Do GATT operations only if this descriptor has been registered.
|
// Do GATT operations only if this descriptor has been registered.
|
||||||
if (self->handle != BLE_GATT_HANDLE_INVALID) {
|
if (self->handle != BLE_GATT_HANDLE_INVALID) {
|
||||||
if (common_hal_bleio_service_get_is_remote(self->characteristic->service)) {
|
if (common_hal_bleio_service_get_is_remote(self->characteristic->service)) {
|
||||||
//FIX
|
// FIX
|
||||||
// uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
|
// uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
|
||||||
// att_write_req(conn_handle, self->handle, bufinfo->buf, bufinfo->len, rsp);
|
// att_write_req(conn_handle, self->handle, bufinfo->buf, bufinfo->len, rsp);
|
||||||
} else {
|
} else {
|
||||||
|
@ -47,7 +47,7 @@ typedef struct _bleio_descriptor_obj {
|
|||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
bleio_attribute_security_mode_t read_perm;
|
bleio_attribute_security_mode_t read_perm;
|
||||||
bleio_attribute_security_mode_t write_perm;
|
bleio_attribute_security_mode_t write_perm;
|
||||||
struct _bleio_descriptor_obj* next;
|
struct _bleio_descriptor_obj *next;
|
||||||
} bleio_descriptor_obj_t;
|
} bleio_descriptor_obj_t;
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_DESCRIPTOR_H
|
#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_DESCRIPTOR_H
|
||||||
|
@ -45,13 +45,13 @@ STATIC void write_to_ringbuf(bleio_packet_buffer_obj_t *self, uint8_t *data, uin
|
|||||||
// Make room for the new value by dropping the oldest packets first.
|
// Make room for the new value by dropping the oldest packets first.
|
||||||
while (ringbuf_capacity(&self->ringbuf) - ringbuf_num_filled(&self->ringbuf) < len + sizeof(uint16_t)) {
|
while (ringbuf_capacity(&self->ringbuf) - ringbuf_num_filled(&self->ringbuf) < len + sizeof(uint16_t)) {
|
||||||
uint16_t packet_length;
|
uint16_t packet_length;
|
||||||
ringbuf_get_n(&self->ringbuf, (uint8_t*) &packet_length, sizeof(uint16_t));
|
ringbuf_get_n(&self->ringbuf, (uint8_t *)&packet_length, sizeof(uint16_t));
|
||||||
for (uint16_t i = 0; i < packet_length; i++) {
|
for (uint16_t i = 0; i < packet_length; i++) {
|
||||||
ringbuf_get(&self->ringbuf);
|
ringbuf_get(&self->ringbuf);
|
||||||
}
|
}
|
||||||
// set an overflow flag?
|
// set an overflow flag?
|
||||||
}
|
}
|
||||||
ringbuf_put_n(&self->ringbuf, (uint8_t*) &len, sizeof(uint16_t));
|
ringbuf_put_n(&self->ringbuf, (uint8_t *)&len, sizeof(uint16_t));
|
||||||
ringbuf_put_n(&self->ringbuf, data, len);
|
ringbuf_put_n(&self->ringbuf, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,8 +80,8 @@ void bleio_packet_buffer_update(bleio_packet_buffer_obj_t *self, mp_buffer_info_
|
|||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_bleio_packet_buffer_construct(
|
void common_hal_bleio_packet_buffer_construct(
|
||||||
bleio_packet_buffer_obj_t *self, bleio_characteristic_obj_t *characteristic,
|
bleio_packet_buffer_obj_t *self, bleio_characteristic_obj_t *characteristic,
|
||||||
size_t buffer_size) {
|
size_t buffer_size) {
|
||||||
|
|
||||||
self->characteristic = characteristic;
|
self->characteristic = characteristic;
|
||||||
self->client = self->characteristic->service->is_remote;
|
self->client = self->characteristic->service->is_remote;
|
||||||
@ -128,7 +128,7 @@ mp_int_t common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self
|
|||||||
// Copy received data.
|
// Copy received data.
|
||||||
// Get packet length, which is in first two bytes of packet.
|
// Get packet length, which is in first two bytes of packet.
|
||||||
uint16_t packet_length;
|
uint16_t packet_length;
|
||||||
ringbuf_get_n(&self->ringbuf, (uint8_t*) &packet_length, sizeof(uint16_t));
|
ringbuf_get_n(&self->ringbuf, (uint8_t *)&packet_length, sizeof(uint16_t));
|
||||||
|
|
||||||
mp_int_t ret;
|
mp_int_t ret;
|
||||||
if (packet_length > len) {
|
if (packet_length > len) {
|
||||||
@ -136,7 +136,7 @@ mp_int_t common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self
|
|||||||
ret = len - packet_length;
|
ret = len - packet_length;
|
||||||
// Discard the packet if it's too large. Don't fill data.
|
// Discard the packet if it's too large. Don't fill data.
|
||||||
while (packet_length--) {
|
while (packet_length--) {
|
||||||
(void) ringbuf_get(&self->ringbuf);
|
(void)ringbuf_get(&self->ringbuf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Read as much as possible, but might be shorter than len.
|
// Read as much as possible, but might be shorter than len.
|
||||||
@ -147,7 +147,7 @@ mp_int_t common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self, uint8_t *data, size_t len, uint8_t* header, size_t header_len) {
|
mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self, uint8_t *data, size_t len, uint8_t *header, size_t header_len) {
|
||||||
if (self->outgoing[0] == NULL) {
|
if (self->outgoing[0] == NULL) {
|
||||||
mp_raise_bleio_BluetoothError(translate("Writes not supported on Characteristic"));
|
mp_raise_bleio_BluetoothError(translate("Writes not supported on Characteristic"));
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self, u
|
|||||||
|
|
||||||
size_t num_bytes_written = 0;
|
size_t num_bytes_written = 0;
|
||||||
|
|
||||||
uint8_t* pending = self->outgoing[self->pending_index];
|
uint8_t *pending = self->outgoing[self->pending_index];
|
||||||
|
|
||||||
if (self->pending_size == 0) {
|
if (self->pending_size == 0) {
|
||||||
memcpy(pending, header, header_len);
|
memcpy(pending, header, header_len);
|
||||||
@ -213,7 +213,7 @@ mp_int_t common_hal_bleio_packet_buffer_get_incoming_packet_length(bleio_packet_
|
|||||||
bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle);
|
bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
return MIN(common_hal_bleio_connection_get_max_packet_length(connection),
|
return MIN(common_hal_bleio_connection_get_max_packet_length(connection),
|
||||||
self->characteristic->max_length);
|
self->characteristic->max_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// There's no current connection, so we don't know the MTU, and
|
// There's no current connection, so we don't know the MTU, and
|
||||||
@ -244,7 +244,7 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_
|
|||||||
bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle);
|
bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
return MIN(common_hal_bleio_connection_get_max_packet_length(connection),
|
return MIN(common_hal_bleio_connection_get_max_packet_length(connection),
|
||||||
self->characteristic->max_length);
|
self->characteristic->max_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// There's no current connection, so we don't know the MTU, and
|
// There's no current connection, so we don't know the MTU, and
|
||||||
|
@ -37,7 +37,7 @@ typedef struct {
|
|||||||
ringbuf_t ringbuf;
|
ringbuf_t ringbuf;
|
||||||
// Two outgoing buffers to alternate between. One will be queued for transmission by the SD and
|
// Two outgoing buffers to alternate between. One will be queued for transmission by the SD and
|
||||||
// the other is waiting to be queued and can be extended.
|
// the other is waiting to be queued and can be extended.
|
||||||
uint8_t* outgoing[2];
|
uint8_t *outgoing[2];
|
||||||
volatile uint16_t pending_size;
|
volatile uint16_t pending_size;
|
||||||
// We remember the conn_handle so we can do a NOTIFY/INDICATE to a client.
|
// We remember the conn_handle so we can do a NOTIFY/INDICATE to a client.
|
||||||
// We can find out the conn_handle on a Characteristic write or a CCCD write (but not a read).
|
// We can find out the conn_handle on a Characteristic write or a CCCD write (but not a read).
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include "shared-bindings/_bleio/Service.h"
|
#include "shared-bindings/_bleio/Service.h"
|
||||||
#include "shared-bindings/_bleio/Adapter.h"
|
#include "shared-bindings/_bleio/Adapter.h"
|
||||||
|
|
||||||
uint32_t _common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, bool is_secondary, mp_obj_list_t * characteristic_list) {
|
uint32_t _common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, bool is_secondary, mp_obj_list_t *characteristic_list) {
|
||||||
self->uuid = uuid;
|
self->uuid = uuid;
|
||||||
self->characteristic_list = characteristic_list;
|
self->characteristic_list = characteristic_list;
|
||||||
self->is_remote = false;
|
self->is_remote = false;
|
||||||
@ -52,7 +52,7 @@ uint32_t _common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uu
|
|||||||
|
|
||||||
void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, bool is_secondary) {
|
void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, bool is_secondary) {
|
||||||
if (_common_hal_bleio_service_construct(self, uuid, is_secondary,
|
if (_common_hal_bleio_service_construct(self, uuid, is_secondary,
|
||||||
mp_obj_new_list(0, NULL)) != 0) {
|
mp_obj_new_list(0, NULL)) != 0) {
|
||||||
mp_raise_RuntimeError(translate("Failed to add service"));
|
mp_raise_RuntimeError(translate("Failed to add service"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,8 +83,8 @@ bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
|
void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
|
||||||
bleio_characteristic_obj_t *characteristic,
|
bleio_characteristic_obj_t *characteristic,
|
||||||
mp_buffer_info_t *initial_value_bufinfo) {
|
mp_buffer_info_t *initial_value_bufinfo) {
|
||||||
|
|
||||||
if (self->handle != common_hal_bleio_adapter_obj.last_added_service_handle) {
|
if (self->handle != common_hal_bleio_adapter_obj.last_added_service_handle) {
|
||||||
mp_raise_bleio_BluetoothError(
|
mp_raise_bleio_BluetoothError(
|
||||||
|
@ -46,7 +46,7 @@ typedef struct bleio_service_obj {
|
|||||||
// Range of attribute handles of this service.
|
// Range of attribute handles of this service.
|
||||||
uint16_t start_handle;
|
uint16_t start_handle;
|
||||||
uint16_t end_handle;
|
uint16_t end_handle;
|
||||||
struct bleio_service_obj* next;
|
struct bleio_service_obj *next;
|
||||||
} bleio_service_obj_t;
|
} bleio_service_obj_t;
|
||||||
|
|
||||||
void bleio_service_from_connection(bleio_service_obj_t *self, mp_obj_t connection);
|
void bleio_service_from_connection(bleio_service_obj_t *self, mp_obj_t connection);
|
||||||
|
@ -60,7 +60,7 @@ void common_hal_bleio_uuid_get_uuid128(bleio_uuid_obj_t *self, uint8_t uuid128[1
|
|||||||
memcpy(uuid128, self->uuid128, 16);
|
memcpy(uuid128, self->uuid128, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_bleio_uuid_pack_into(bleio_uuid_obj_t *self, uint8_t* buf) {
|
void common_hal_bleio_uuid_pack_into(bleio_uuid_obj_t *self, uint8_t *buf) {
|
||||||
if (self->size == 16) {
|
if (self->size == 16) {
|
||||||
buf[0] = self->uuid16 & 0xff;
|
buf[0] = self->uuid16 & 0xff;
|
||||||
buf[1] = self->uuid16 >> 8;
|
buf[1] = self->uuid16 >> 8;
|
||||||
|
@ -33,17 +33,17 @@
|
|||||||
|
|
||||||
// Types returned by attribute table lookups. These are UUIDs.
|
// Types returned by attribute table lookups. These are UUIDs.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BLE_UUID_UNKNOWN = 0x0000,
|
BLE_UUID_UNKNOWN = 0x0000,
|
||||||
BLE_UUID_SERVICE_PRIMARY = 0x2800,
|
BLE_UUID_SERVICE_PRIMARY = 0x2800,
|
||||||
BLE_UUID_SERVICE_SECONDARY = 0x2801,
|
BLE_UUID_SERVICE_SECONDARY = 0x2801,
|
||||||
BLE_UUID_SERVICE_INCLUDE = 0x2802, // not yet implemented by us
|
BLE_UUID_SERVICE_INCLUDE = 0x2802,// not yet implemented by us
|
||||||
BLE_UUID_CHARACTERISTIC = 0x2803,
|
BLE_UUID_CHARACTERISTIC = 0x2803,
|
||||||
BLE_UUID_CHAR_EXTENDED_PROPS = 0x2900, // not yet implemented by us
|
BLE_UUID_CHAR_EXTENDED_PROPS = 0x2900,// not yet implemented by us
|
||||||
BLE_UUID_CHAR_USER_DESC = 0x2901, // not yet implemented by us
|
BLE_UUID_CHAR_USER_DESC = 0x2901,// not yet implemented by us
|
||||||
BLE_UUID_CCCD = 0x2902,
|
BLE_UUID_CCCD = 0x2902,
|
||||||
BLE_UUID_SCCD = 0x2903, // not yet implemented by us
|
BLE_UUID_SCCD = 0x2903,// not yet implemented by us
|
||||||
BLE_UUID_CHAR_PRESENTATION_FMT = 0x2904, // not yet implemented by us
|
BLE_UUID_CHAR_PRESENTATION_FMT = 0x2904, // not yet implemented by us
|
||||||
BLE_UUID_CHAR_AGGREGATE_FMT = 0x2905, // not yet implemented by us
|
BLE_UUID_CHAR_AGGREGATE_FMT = 0x2905,// not yet implemented by us
|
||||||
} ble_standard_uuid;
|
} ble_standard_uuid;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -78,7 +78,7 @@ void bleio_reset() {
|
|||||||
|
|
||||||
bleio_set_adapter(mp_const_none);
|
bleio_set_adapter(mp_const_none);
|
||||||
|
|
||||||
//FIX bonding_reset();
|
// FIX bonding_reset();
|
||||||
supervisor_start_bluetooth();
|
supervisor_start_bluetooth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ typedef struct {
|
|||||||
// 20 bytes max (23 - 3).
|
// 20 bytes max (23 - 3).
|
||||||
#define GATT_MAX_DATA_LENGTH (BT_ATT_DEFAULT_LE_MTU - 3)
|
#define GATT_MAX_DATA_LENGTH (BT_ATT_DEFAULT_LE_MTU - 3)
|
||||||
|
|
||||||
//FIX
|
// FIX
|
||||||
#define BLE_GATT_HANDLE_INVALID 0x0000
|
#define BLE_GATT_HANDLE_INVALID 0x0000
|
||||||
#define BLE_CONN_HANDLE_INVALID 0xFFFF
|
#define BLE_CONN_HANDLE_INVALID 0xFFFF
|
||||||
#define BLE_GATTS_FIX_ATTR_LEN_MAX (510) /**< Maximum length for fixed length Attribute Values. */
|
#define BLE_GATTS_FIX_ATTR_LEN_MAX (510) /**< Maximum length for fixed length Attribute Values. */
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
#include "att.h"
|
#include "att.h"
|
||||||
|
|
||||||
// Zephyr include files to define HCI communication values and structs.
|
// Zephyr include files to define HCI communication values and structs.
|
||||||
//#include "hci_include/hci.h"
|
// #include "hci_include/hci.h"
|
||||||
//#include "hci_include/hci_err.h"
|
// #include "hci_include/hci_err.h"
|
||||||
#include "hci_include/l2cap_internal.h"
|
#include "hci_include/l2cap_internal.h"
|
||||||
|
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
@ -44,7 +44,7 @@ STATIC unsigned long timeout = 5000;
|
|||||||
STATIC volatile bool confirm;
|
STATIC volatile bool confirm;
|
||||||
|
|
||||||
STATIC uint16_t long_write_handle = BLE_GATT_HANDLE_INVALID;
|
STATIC uint16_t long_write_handle = BLE_GATT_HANDLE_INVALID;
|
||||||
STATIC uint8_t* long_write_value = NULL;
|
STATIC uint8_t *long_write_value = NULL;
|
||||||
STATIC uint16_t long_write_value_length = 0;
|
STATIC uint16_t long_write_value_length = 0;
|
||||||
|
|
||||||
// When we send a request, fill this struct with info about the expected response.
|
// When we send a request, fill this struct with info about the expected response.
|
||||||
@ -52,7 +52,7 @@ STATIC uint16_t long_write_value_length = 0;
|
|||||||
STATIC struct {
|
STATIC struct {
|
||||||
uint16_t conn_handle; // Expected handle.
|
uint16_t conn_handle; // Expected handle.
|
||||||
uint8_t opcode; // Expected RSP opcode.
|
uint8_t opcode; // Expected RSP opcode.
|
||||||
uint8_t* buffer; // Pointer to response packet
|
uint8_t *buffer; // Pointer to response packet
|
||||||
uint8_t length; // Length of response packet.
|
uint8_t length; // Length of response packet.
|
||||||
} expected_rsp;
|
} expected_rsp;
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ STATIC uint8_t bleio_properties_to_ble_spec_properties(uint8_t bleio_properties)
|
|||||||
return ble_spec_properties;
|
return ble_spec_properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIX not currently used; reenable when used.
|
// FIX not currently used; reenable when used.
|
||||||
#if 0
|
#if 0
|
||||||
STATIC uint8_t ble_spec_properties_to_bleio_properties(uint8_t ble_spec_properties) {
|
STATIC uint8_t ble_spec_properties_to_bleio_properties(uint8_t ble_spec_properties) {
|
||||||
uint8_t bleio_properties = 0;
|
uint8_t bleio_properties = 0;
|
||||||
@ -120,20 +120,19 @@ STATIC void send_error(uint16_t conn_handle, uint8_t opcode, uint16_t handle, ui
|
|||||||
struct bt_att_hdr h;
|
struct bt_att_hdr h;
|
||||||
struct bt_att_error_rsp r;
|
struct bt_att_error_rsp r;
|
||||||
} rsp = { {
|
} rsp = { {
|
||||||
.code = BT_ATT_OP_ERROR_RSP,
|
.code = BT_ATT_OP_ERROR_RSP,
|
||||||
}, {
|
}, {
|
||||||
.request = opcode,
|
.request = opcode,
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
|
|
||||||
hci_send_acl_pkt(conn_handle, BT_L2CAP_CID_ATT, sizeof(rsp), (uint8_t *) &rsp);
|
hci_send_acl_pkt(conn_handle, BT_L2CAP_CID_ATT, sizeof(rsp), (uint8_t *)&rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void send_req(uint16_t conn_handle, size_t request_length, uint8_t* request_buffer) {
|
STATIC void send_req(uint16_t conn_handle, size_t request_length, uint8_t *request_buffer) {
|
||||||
hci_send_acl_pkt(conn_handle, BT_L2CAP_CID_ATT, request_length, request_buffer);
|
hci_send_acl_pkt(conn_handle, BT_L2CAP_CID_ATT, request_length, request_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int send_req_wait_for_rsp(uint16_t conn_handle, size_t request_length, uint8_t* request_buffer, uint8_t response_buffer[]) {
|
STATIC int send_req_wait_for_rsp(uint16_t conn_handle, size_t request_length, uint8_t *request_buffer, uint8_t response_buffer[]) {
|
||||||
// We expect a particular kind of response after this request.
|
// We expect a particular kind of response after this request.
|
||||||
expected_rsp.conn_handle = conn_handle;
|
expected_rsp.conn_handle = conn_handle;
|
||||||
// The response opcode is the request opcode + 1.
|
// The response opcode is the request opcode + 1.
|
||||||
@ -192,9 +191,9 @@ void bleio_att_reset(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool att_connect_to_address(bt_addr_le_t *addr) {
|
bool att_connect_to_address(bt_addr_le_t *addr) {
|
||||||
//FIX
|
// FIX
|
||||||
if (hci_le_create_conn(0x0060, 0x0030, 0x00, addr, 0x00,
|
if (hci_le_create_conn(0x0060, 0x0030, 0x00, addr, 0x00,
|
||||||
0x0006, 0x000c, 0x0000, 0x00c8, 0x0004, 0x0006) != 0) {
|
0x0006, 0x000c, 0x0000, 0x00c8, 0x0004, 0x0006) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +228,7 @@ bool att_disconnect(uint16_t conn_handle) {
|
|||||||
return !att_handle_is_connected(conn_handle);
|
return !att_handle_is_connected(conn_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIX
|
// FIX
|
||||||
// STATIC bool discover_services(uint16_t conn_handle, BLERemoteDevice* device, const char* serviceUuidFilter) {
|
// STATIC bool discover_services(uint16_t conn_handle, BLERemoteDevice* device, const char* serviceUuidFilter) {
|
||||||
// uint16_t reqStart_handle = 0x0001;
|
// uint16_t reqStart_handle = 0x0001;
|
||||||
// uint16_t reqEnd_handle = 0xffff;
|
// uint16_t reqEnd_handle = 0xffff;
|
||||||
@ -406,7 +405,7 @@ bool att_disconnect(uint16_t conn_handle) {
|
|||||||
// return true;
|
// return true;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
bool att_discover_attributes(bt_addr_le_t *addr, const char* service_uuid_filter) {
|
bool att_discover_attributes(bt_addr_le_t *addr, const char *service_uuid_filter) {
|
||||||
uint16_t conn_handle = att_conn_handle(addr);
|
uint16_t conn_handle = att_conn_handle(addr);
|
||||||
if (conn_handle == 0xffff) {
|
if (conn_handle == 0xffff) {
|
||||||
return false;
|
return false;
|
||||||
@ -418,7 +417,7 @@ bool att_discover_attributes(bt_addr_le_t *addr, const char* service_uuid_filter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find the device entry for the peeer
|
// find the device entry for the peeer
|
||||||
//FIX BLERemoteDevice* device = NULL;
|
// FIX BLERemoteDevice* device = NULL;
|
||||||
|
|
||||||
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
||||||
// if (bleio_connections[i].conn_handle == conn_handle) {
|
// if (bleio_connections[i].conn_handle == conn_handle) {
|
||||||
@ -454,7 +453,7 @@ bool att_discover_attributes(bt_addr_le_t *addr, const char* service_uuid_filter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// discover services
|
// discover services
|
||||||
//FIX
|
// FIX
|
||||||
// if (!att_discover_services(conn_handle, device, service_uuid_filter)) {
|
// if (!att_discover_services(conn_handle, device, service_uuid_filter)) {
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
@ -481,10 +480,10 @@ void att_set_timeout(unsigned long timeout_in) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void att_add_connection(uint16_t handle, uint8_t role, bt_addr_le_t *peer_addr, uint16_t interval, uint16_t latency, uint16_t supervision_timeout, uint8_t master_clock_accuracy) {
|
void att_add_connection(uint16_t handle, uint8_t role, bt_addr_le_t *peer_addr, uint16_t interval, uint16_t latency, uint16_t supervision_timeout, uint8_t master_clock_accuracy) {
|
||||||
(void) interval;
|
(void)interval;
|
||||||
(void) latency;
|
(void)latency;
|
||||||
(void) supervision_timeout;
|
(void)supervision_timeout;
|
||||||
(void) master_clock_accuracy;
|
(void)master_clock_accuracy;
|
||||||
|
|
||||||
int peer_index = -1;
|
int peer_index = -1;
|
||||||
|
|
||||||
@ -508,7 +507,7 @@ void att_add_connection(uint16_t handle, uint8_t role, bt_addr_le_t *peer_addr,
|
|||||||
|
|
||||||
|
|
||||||
void att_remove_connection(uint16_t conn_handle, uint8_t reason) {
|
void att_remove_connection(uint16_t conn_handle, uint8_t reason) {
|
||||||
(void) reason;
|
(void)reason;
|
||||||
int peer_index = -1;
|
int peer_index = -1;
|
||||||
int peer_count = 0;
|
int peer_count = 0;
|
||||||
|
|
||||||
@ -580,7 +579,7 @@ bool att_is_connected(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool att_address_is_connected(bt_addr_le_t *addr) {
|
bool att_address_is_connected(bt_addr_le_t *addr) {
|
||||||
return (att_conn_handle(addr) != 0xffff);
|
return att_conn_handle(addr) != 0xffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool att_handle_is_connected(uint16_t handle) {
|
bool att_handle_is_connected(uint16_t handle) {
|
||||||
@ -624,10 +623,10 @@ bool att_disconnect_all(void) {
|
|||||||
bleio_connections[i].mtu = BT_ATT_DEFAULT_LE_MTU;
|
bleio_connections[i].mtu = BT_ATT_DEFAULT_LE_MTU;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (num_disconnects > 0);
|
return num_disconnects > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool att_notify(uint16_t handle, const uint8_t* value, int length) {
|
bool att_notify(uint16_t handle, const uint8_t *value, int length) {
|
||||||
int num_notifications = 0;
|
int num_notifications = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
||||||
@ -643,20 +642,21 @@ bool att_notify(uint16_t handle, const uint8_t* value, int length) {
|
|||||||
size_t allowed_length = MIN((uint16_t)(bleio_connections[i].mtu - sizeof(notify_t)), (uint16_t)length);
|
size_t allowed_length = MIN((uint16_t)(bleio_connections[i].mtu - sizeof(notify_t)), (uint16_t)length);
|
||||||
|
|
||||||
uint8_t notify_bytes[sizeof(notify_t) + allowed_length];
|
uint8_t notify_bytes[sizeof(notify_t) + allowed_length];
|
||||||
notify_t *notify = (notify_t *) notify_bytes;
|
notify_t *notify = (notify_t *)notify_bytes;
|
||||||
notify->hdr.code = BT_ATT_OP_NOTIFY;;
|
notify->hdr.code = BT_ATT_OP_NOTIFY;
|
||||||
|
;
|
||||||
notify->ntf.handle = handle;
|
notify->ntf.handle = handle;
|
||||||
memcpy(notify->ntf.value, value, allowed_length);
|
memcpy(notify->ntf.value, value, allowed_length);
|
||||||
hci_send_acl_pkt(bleio_connections[i].conn_handle, BT_L2CAP_CID_ATT,
|
hci_send_acl_pkt(bleio_connections[i].conn_handle, BT_L2CAP_CID_ATT,
|
||||||
sizeof(notify_bytes), notify_bytes);
|
sizeof(notify_bytes), notify_bytes);
|
||||||
|
|
||||||
num_notifications++;
|
num_notifications++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (num_notifications > 0);
|
return num_notifications > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool att_indicate(uint16_t handle, const uint8_t* value, int length) {
|
bool att_indicate(uint16_t handle, const uint8_t *value, int length) {
|
||||||
int num_indications = 0;
|
int num_indications = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
||||||
@ -672,15 +672,16 @@ bool att_indicate(uint16_t handle, const uint8_t* value, int length) {
|
|||||||
size_t allowed_length = MIN((uint16_t)(bleio_connections[i].mtu - sizeof(indicate_t)), (uint16_t)length);
|
size_t allowed_length = MIN((uint16_t)(bleio_connections[i].mtu - sizeof(indicate_t)), (uint16_t)length);
|
||||||
|
|
||||||
uint8_t indicate_bytes[sizeof(indicate_t) + allowed_length];
|
uint8_t indicate_bytes[sizeof(indicate_t) + allowed_length];
|
||||||
indicate_t *indicate = (indicate_t *) indicate_bytes;
|
indicate_t *indicate = (indicate_t *)indicate_bytes;
|
||||||
indicate->hdr.code = BT_ATT_OP_INDICATE;;
|
indicate->hdr.code = BT_ATT_OP_INDICATE;
|
||||||
|
;
|
||||||
indicate->ind.handle = handle;
|
indicate->ind.handle = handle;
|
||||||
memcpy(indicate->ind.value, value, allowed_length);
|
memcpy(indicate->ind.value, value, allowed_length);
|
||||||
|
|
||||||
confirm = false;
|
confirm = false;
|
||||||
|
|
||||||
hci_send_acl_pkt(bleio_connections[i].conn_handle, BT_L2CAP_CID_ATT,
|
hci_send_acl_pkt(bleio_connections[i].conn_handle, BT_L2CAP_CID_ATT,
|
||||||
sizeof(indicate_bytes), indicate_bytes);
|
sizeof(indicate_bytes), indicate_bytes);
|
||||||
|
|
||||||
while (!confirm) {
|
while (!confirm) {
|
||||||
// RUN_BACKGROUND_TASKS includes hci_poll_for_incoming_pkt();
|
// RUN_BACKGROUND_TASKS includes hci_poll_for_incoming_pkt();
|
||||||
@ -694,11 +695,11 @@ bool att_indicate(uint16_t handle, const uint8_t* value, int length) {
|
|||||||
num_indications++;
|
num_indications++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (num_indications > 0);
|
return num_indications > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_error(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_error(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
||||||
struct bt_att_error_rsp *rsp = (struct bt_att_error_rsp *) data;
|
struct bt_att_error_rsp *rsp = (struct bt_att_error_rsp *)data;
|
||||||
|
|
||||||
if (dlen != sizeof(struct bt_att_error_rsp)) {
|
if (dlen != sizeof(struct bt_att_error_rsp)) {
|
||||||
// Incorrect size; ignore.
|
// Incorrect size; ignore.
|
||||||
@ -714,7 +715,7 @@ STATIC void process_error(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_mtu_req(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_mtu_req(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
||||||
struct bt_att_exchange_mtu_req *req = (struct bt_att_exchange_mtu_req *) data;
|
struct bt_att_exchange_mtu_req *req = (struct bt_att_exchange_mtu_req *)data;
|
||||||
|
|
||||||
if (dlen != sizeof(struct bt_att_exchange_mtu_req)) {
|
if (dlen != sizeof(struct bt_att_exchange_mtu_req)) {
|
||||||
send_error(conn_handle, BT_ATT_OP_MTU_REQ, BLE_GATT_HANDLE_INVALID, BT_ATT_ERR_INVALID_PDU);
|
send_error(conn_handle, BT_ATT_OP_MTU_REQ, BLE_GATT_HANDLE_INVALID, BT_ATT_ERR_INVALID_PDU);
|
||||||
@ -738,17 +739,16 @@ STATIC void process_mtu_req(uint16_t conn_handle, uint8_t dlen, uint8_t data[])
|
|||||||
struct bt_att_hdr h;
|
struct bt_att_hdr h;
|
||||||
struct bt_att_exchange_mtu_rsp r;
|
struct bt_att_exchange_mtu_rsp r;
|
||||||
} rsp = { {
|
} rsp = { {
|
||||||
.code = BT_ATT_OP_MTU_RSP,
|
.code = BT_ATT_OP_MTU_RSP,
|
||||||
}, {
|
}, {
|
||||||
.mtu = mtu,
|
.mtu = mtu,
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
|
|
||||||
hci_send_acl_pkt(conn_handle, BT_L2CAP_CID_ATT, sizeof(rsp), (uint8_t *) &rsp);
|
hci_send_acl_pkt(conn_handle, BT_L2CAP_CID_ATT, sizeof(rsp), (uint8_t *)&rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_mtu_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_mtu_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
||||||
struct bt_att_exchange_mtu_rsp *rsp = (struct bt_att_exchange_mtu_rsp *) data;
|
struct bt_att_exchange_mtu_rsp *rsp = (struct bt_att_exchange_mtu_rsp *)data;
|
||||||
|
|
||||||
if (dlen != sizeof(struct bt_att_exchange_mtu_rsp)) {
|
if (dlen != sizeof(struct bt_att_exchange_mtu_rsp)) {
|
||||||
return;
|
return;
|
||||||
@ -765,7 +765,7 @@ STATIC void process_mtu_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_find_info_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_find_info_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
||||||
struct bt_att_find_info_req *req = (struct bt_att_find_info_req *) data;
|
struct bt_att_find_info_req *req = (struct bt_att_find_info_req *)data;
|
||||||
|
|
||||||
if (dlen != sizeof(struct bt_att_find_info_req)) {
|
if (dlen != sizeof(struct bt_att_find_info_req)) {
|
||||||
send_error(conn_handle, BT_ATT_OP_FIND_INFO_REQ, req->start_handle, BT_ATT_ERR_INVALID_PDU);
|
send_error(conn_handle, BT_ATT_OP_FIND_INFO_REQ, req->start_handle, BT_ATT_ERR_INVALID_PDU);
|
||||||
@ -778,7 +778,7 @@ STATIC void process_find_info_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
|||||||
} rsp_t;
|
} rsp_t;
|
||||||
|
|
||||||
uint8_t rsp_bytes[mtu];
|
uint8_t rsp_bytes[mtu];
|
||||||
rsp_t *rsp = (rsp_t *) rsp_bytes;
|
rsp_t *rsp = (rsp_t *)rsp_bytes;
|
||||||
rsp->h.code = BT_ATT_OP_FIND_INFO_RSP;
|
rsp->h.code = BT_ATT_OP_FIND_INFO_RSP;
|
||||||
|
|
||||||
// Keeps track of total length of the response.
|
// Keeps track of total length of the response.
|
||||||
@ -832,20 +832,20 @@ STATIC void process_find_info_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sizeof_uuid == 2) {
|
if (sizeof_uuid == 2) {
|
||||||
struct bt_att_info_16 *info_16 = (struct bt_att_info_16 *) &rsp_bytes[rsp_length];
|
struct bt_att_info_16 *info_16 = (struct bt_att_info_16 *)&rsp_bytes[rsp_length];
|
||||||
info_16->handle = handle;
|
info_16->handle = handle;
|
||||||
info_16->uuid = common_hal_bleio_uuid_get_uuid16(uuid);
|
info_16->uuid = common_hal_bleio_uuid_get_uuid16(uuid);
|
||||||
|
|
||||||
rsp_length += sizeof(struct bt_att_info_16);
|
rsp_length += sizeof(struct bt_att_info_16);
|
||||||
} else {
|
} else {
|
||||||
struct bt_att_info_128 *info_128 = (struct bt_att_info_128 *) &rsp_bytes[rsp_length];
|
struct bt_att_info_128 *info_128 = (struct bt_att_info_128 *)&rsp_bytes[rsp_length];
|
||||||
info_128->handle = handle;
|
info_128->handle = handle;
|
||||||
common_hal_bleio_uuid_get_uuid128(uuid, info_128->uuid);
|
common_hal_bleio_uuid_get_uuid128(uuid, info_128->uuid);
|
||||||
|
|
||||||
rsp_length += sizeof(struct bt_att_info_128);
|
rsp_length += sizeof(struct bt_att_info_128);
|
||||||
}
|
}
|
||||||
|
|
||||||
no_data =false;
|
no_data = false;
|
||||||
} // end for
|
} // end for
|
||||||
|
|
||||||
|
|
||||||
@ -861,14 +861,13 @@ int att_find_info_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_
|
|||||||
struct bt_att_hdr h;
|
struct bt_att_hdr h;
|
||||||
struct bt_att_find_info_req r;
|
struct bt_att_find_info_req r;
|
||||||
} req = { {
|
} req = { {
|
||||||
.code = BT_ATT_OP_FIND_INFO_REQ,
|
.code = BT_ATT_OP_FIND_INFO_REQ,
|
||||||
}, {
|
}, {
|
||||||
.start_handle = start_handle,
|
.start_handle = start_handle,
|
||||||
.end_handle = end_handle,
|
.end_handle = end_handle,
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
|
|
||||||
return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *) &req, response_buffer);
|
return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *)&req, response_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_find_info_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_find_info_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
||||||
@ -880,7 +879,7 @@ STATIC void process_find_info_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t da
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_find_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_find_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
||||||
struct bt_att_find_type_req *req = (struct bt_att_find_type_req *) data;
|
struct bt_att_find_type_req *req = (struct bt_att_find_type_req *)data;
|
||||||
|
|
||||||
if (dlen < sizeof(struct bt_att_find_type_req)) {
|
if (dlen < sizeof(struct bt_att_find_type_req)) {
|
||||||
send_error(conn_handle, BT_ATT_OP_FIND_TYPE_RSP, req->start_handle, BT_ATT_ERR_INVALID_PDU);
|
send_error(conn_handle, BT_ATT_OP_FIND_TYPE_RSP, req->start_handle, BT_ATT_ERR_INVALID_PDU);
|
||||||
@ -893,7 +892,7 @@ STATIC void process_find_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
|||||||
response[0] = BT_ATT_OP_FIND_TYPE_RSP;
|
response[0] = BT_ATT_OP_FIND_TYPE_RSP;
|
||||||
response_length = 1;
|
response_length = 1;
|
||||||
|
|
||||||
//FIX
|
// FIX
|
||||||
// if (find_type_req->type == BLE_UUID_SERVICE_PRIMARY) {
|
// if (find_type_req->type == BLE_UUID_SERVICE_PRIMARY) {
|
||||||
// for (uint16_t i = (find_type_req->start_handle - 1); i < GATT.attributeCount() && i <= (find_type_req->end_handle - 1); i++) {
|
// for (uint16_t i = (find_type_req->start_handle - 1); i < GATT.attributeCount() && i <= (find_type_req->end_handle - 1); i++) {
|
||||||
// BLELocalAttribute* attribute = GATT.attribute(i);
|
// BLELocalAttribute* attribute = GATT.attribute(i);
|
||||||
@ -926,7 +925,7 @@ STATIC void process_find_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
|||||||
}
|
}
|
||||||
|
|
||||||
void process_read_group_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
void process_read_group_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
||||||
struct bt_att_read_group_req *req = (struct bt_att_read_group_req *) data;
|
struct bt_att_read_group_req *req = (struct bt_att_read_group_req *)data;
|
||||||
uint16_t type_uuid = req->uuid[0] | (req->uuid[1] << 8);
|
uint16_t type_uuid = req->uuid[0] | (req->uuid[1] << 8);
|
||||||
|
|
||||||
// We only support returning services for BT_ATT_OP_READ_GROUP_REQ, which is typically used
|
// We only support returning services for BT_ATT_OP_READ_GROUP_REQ, which is typically used
|
||||||
@ -944,7 +943,7 @@ void process_read_group_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, ui
|
|||||||
} rsp_t;
|
} rsp_t;
|
||||||
|
|
||||||
uint8_t rsp_bytes[mtu];
|
uint8_t rsp_bytes[mtu];
|
||||||
rsp_t *rsp = (rsp_t *) rsp_bytes;
|
rsp_t *rsp = (rsp_t *)rsp_bytes;
|
||||||
rsp->h.code = BT_ATT_OP_READ_GROUP_RSP;
|
rsp->h.code = BT_ATT_OP_READ_GROUP_RSP;
|
||||||
rsp->r.len = 0;
|
rsp->r.len = 0;
|
||||||
|
|
||||||
@ -991,7 +990,7 @@ void process_read_group_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, ui
|
|||||||
// There may be multiple chunks in this transmission.
|
// There may be multiple chunks in this transmission.
|
||||||
rsp->r.len = data_length;
|
rsp->r.len = data_length;
|
||||||
|
|
||||||
struct bt_att_group_data *group_data = (struct bt_att_group_data *) &rsp_bytes[rsp_length];
|
struct bt_att_group_data *group_data = (struct bt_att_group_data *)&rsp_bytes[rsp_length];
|
||||||
|
|
||||||
group_data->start_handle = service->start_handle;
|
group_data->start_handle = service->start_handle;
|
||||||
group_data->end_handle = service->end_handle;
|
group_data->end_handle = service->end_handle;
|
||||||
@ -1017,7 +1016,7 @@ int att_read_group_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end
|
|||||||
} req_t;
|
} req_t;
|
||||||
|
|
||||||
uint8_t req_bytes[sizeof(req_t) + sizeof(uuid)];
|
uint8_t req_bytes[sizeof(req_t) + sizeof(uuid)];
|
||||||
req_t *req = (req_t *) req_bytes;
|
req_t *req = (req_t *)req_bytes;
|
||||||
|
|
||||||
req->h.code = BT_ATT_OP_READ_GROUP_REQ;
|
req->h.code = BT_ATT_OP_READ_GROUP_REQ;
|
||||||
req->r.start_handle = start_handle;
|
req->r.start_handle = start_handle;
|
||||||
@ -1047,7 +1046,7 @@ STATIC void process_read_or_read_blob_req(uint16_t conn_handle, uint16_t mtu, ui
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bt_att_read_req *req = (struct bt_att_read_req *) data;
|
struct bt_att_read_req *req = (struct bt_att_read_req *)data;
|
||||||
handle = req->handle;
|
handle = req->handle;
|
||||||
response_opcode = BT_ATT_OP_READ_RSP;
|
response_opcode = BT_ATT_OP_READ_RSP;
|
||||||
|
|
||||||
@ -1057,7 +1056,7 @@ STATIC void process_read_or_read_blob_req(uint16_t conn_handle, uint16_t mtu, ui
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bt_att_read_blob_req *req = (struct bt_att_read_blob_req *) data;
|
struct bt_att_read_blob_req *req = (struct bt_att_read_blob_req *)data;
|
||||||
handle = req->handle;
|
handle = req->handle;
|
||||||
offset = req->offset;
|
offset = req->offset;
|
||||||
response_opcode = BT_ATT_OP_READ_BLOB_RSP;
|
response_opcode = BT_ATT_OP_READ_BLOB_RSP;
|
||||||
@ -1077,7 +1076,7 @@ STATIC void process_read_or_read_blob_req(uint16_t conn_handle, uint16_t mtu, ui
|
|||||||
} rsp_t;
|
} rsp_t;
|
||||||
|
|
||||||
uint8_t rsp_bytes[mtu];
|
uint8_t rsp_bytes[mtu];
|
||||||
rsp_t *rsp = (rsp_t *) rsp_bytes;
|
rsp_t *rsp = (rsp_t *)rsp_bytes;
|
||||||
rsp->h.code = response_opcode;
|
rsp->h.code = response_opcode;
|
||||||
|
|
||||||
// Keeps track of total length of the response.
|
// Keeps track of total length of the response.
|
||||||
@ -1105,7 +1104,7 @@ STATIC void process_read_or_read_blob_req(uint16_t conn_handle, uint16_t mtu, ui
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
characteristic_declaration_t *char_decl = (characteristic_declaration_t *) rsp->r.value;
|
characteristic_declaration_t *char_decl = (characteristic_declaration_t *)rsp->r.value;
|
||||||
|
|
||||||
// Convert from the bleio properties bit values to the BLE spec properties bit values.
|
// Convert from the bleio properties bit values to the BLE spec properties bit values.
|
||||||
// They are not the same :(.
|
// They are not the same :(.
|
||||||
@ -1160,7 +1159,7 @@ STATIC void process_read_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
||||||
struct bt_att_read_type_req *req = (struct bt_att_read_type_req *) data;
|
struct bt_att_read_type_req *req = (struct bt_att_read_type_req *)data;
|
||||||
uint16_t type_uuid = req->uuid[0] | (req->uuid[1] << 8);
|
uint16_t type_uuid = req->uuid[0] | (req->uuid[1] << 8);
|
||||||
|
|
||||||
if (dlen != sizeof(struct bt_att_read_type_req) + sizeof(type_uuid)) {
|
if (dlen != sizeof(struct bt_att_read_type_req) + sizeof(type_uuid)) {
|
||||||
@ -1174,7 +1173,7 @@ STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
|||||||
} rsp_t;
|
} rsp_t;
|
||||||
|
|
||||||
uint8_t rsp_bytes[mtu];
|
uint8_t rsp_bytes[mtu];
|
||||||
rsp_t *rsp = (rsp_t *) rsp_bytes;
|
rsp_t *rsp = (rsp_t *)rsp_bytes;
|
||||||
rsp->h.code = BT_ATT_OP_READ_TYPE_RSP;
|
rsp->h.code = BT_ATT_OP_READ_TYPE_RSP;
|
||||||
rsp->r.len = 0;
|
rsp->r.len = 0;
|
||||||
|
|
||||||
@ -1233,11 +1232,11 @@ STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
|||||||
// There may be multiple chunks in this transmission.
|
// There may be multiple chunks in this transmission.
|
||||||
rsp->r.len = data_length;
|
rsp->r.len = data_length;
|
||||||
|
|
||||||
struct bt_att_data *att_data = (struct bt_att_data *) &rsp_bytes[rsp_length];
|
struct bt_att_data *att_data = (struct bt_att_data *)&rsp_bytes[rsp_length];
|
||||||
|
|
||||||
att_data->handle = characteristic->decl_handle;
|
att_data->handle = characteristic->decl_handle;
|
||||||
|
|
||||||
characteristic_declaration_t *char_decl = (characteristic_declaration_t *) att_data->value;
|
characteristic_declaration_t *char_decl = (characteristic_declaration_t *)att_data->value;
|
||||||
|
|
||||||
// Convert from the bleio properties bit values to the BLE spec properties bit values.
|
// Convert from the bleio properties bit values to the BLE spec properties bit values.
|
||||||
// They are not the same :(.
|
// They are not the same :(.
|
||||||
@ -1255,7 +1254,7 @@ STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
|||||||
// See if request is for a descriptor value with a 16-bit UUID, such as the CCCD.
|
// See if request is for a descriptor value with a 16-bit UUID, such as the CCCD.
|
||||||
bleio_descriptor_obj_t *descriptor = MP_OBJ_TO_PTR(attribute_obj);
|
bleio_descriptor_obj_t *descriptor = MP_OBJ_TO_PTR(attribute_obj);
|
||||||
if (bleio_uuid_get_uuid16_or_unknown(descriptor->uuid) == type_uuid) {
|
if (bleio_uuid_get_uuid16_or_unknown(descriptor->uuid) == type_uuid) {
|
||||||
struct bt_att_data *att_data = (struct bt_att_data *) &rsp_bytes[rsp_length];
|
struct bt_att_data *att_data = (struct bt_att_data *)&rsp_bytes[rsp_length];
|
||||||
|
|
||||||
att_data->handle = handle;
|
att_data->handle = handle;
|
||||||
|
|
||||||
@ -1277,7 +1276,7 @@ STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
|||||||
bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(attribute_obj);
|
bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(attribute_obj);
|
||||||
if (bleio_uuid_get_uuid16_or_unknown(characteristic->uuid) == type_uuid) {
|
if (bleio_uuid_get_uuid16_or_unknown(characteristic->uuid) == type_uuid) {
|
||||||
|
|
||||||
struct bt_att_data *att_data = (struct bt_att_data *) &rsp_bytes[rsp_length];
|
struct bt_att_data *att_data = (struct bt_att_data *)&rsp_bytes[rsp_length];
|
||||||
|
|
||||||
att_data->handle = handle;
|
att_data->handle = handle;
|
||||||
|
|
||||||
@ -1299,7 +1298,7 @@ STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
|||||||
|
|
||||||
if (no_data) {
|
if (no_data) {
|
||||||
send_error(conn_handle, BT_ATT_OP_READ_TYPE_REQ,
|
send_error(conn_handle, BT_ATT_OP_READ_TYPE_REQ,
|
||||||
req->start_handle, BT_ATT_ERR_ATTRIBUTE_NOT_FOUND);
|
req->start_handle, BT_ATT_ERR_ATTRIBUTE_NOT_FOUND);
|
||||||
} else {
|
} else {
|
||||||
hci_send_acl_pkt(conn_handle, BT_L2CAP_CID_ATT, rsp_length, rsp_bytes);
|
hci_send_acl_pkt(conn_handle, BT_L2CAP_CID_ATT, rsp_length, rsp_bytes);
|
||||||
}
|
}
|
||||||
@ -1312,7 +1311,7 @@ int att_read_type_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_
|
|||||||
} req_t;
|
} req_t;
|
||||||
|
|
||||||
uint8_t req_bytes[sizeof(req_t) + sizeof(type)];
|
uint8_t req_bytes[sizeof(req_t) + sizeof(type)];
|
||||||
req_t *req = (req_t *) req_bytes;
|
req_t *req = (req_t *)req_bytes;
|
||||||
|
|
||||||
req->h.code = BT_ATT_OP_READ_TYPE_REQ;
|
req->h.code = BT_ATT_OP_READ_TYPE_REQ;
|
||||||
req->r.start_handle = start_handle;
|
req->r.start_handle = start_handle;
|
||||||
@ -1334,7 +1333,7 @@ STATIC void process_read_type_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t da
|
|||||||
// Handles BT_ATT_OP_WRITE_REQ or BT_ATT_OP_WRITE_
|
// Handles BT_ATT_OP_WRITE_REQ or BT_ATT_OP_WRITE_
|
||||||
STATIC void process_write_req_or_cmd(uint16_t conn_handle, uint16_t mtu, uint8_t op, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_write_req_or_cmd(uint16_t conn_handle, uint16_t mtu, uint8_t op, uint8_t dlen, uint8_t data[]) {
|
||||||
// struct bt_att_write_cmd is identical, so don't bother to split code paths based on opcode.
|
// struct bt_att_write_cmd is identical, so don't bother to split code paths based on opcode.
|
||||||
struct bt_att_write_req *req = (struct bt_att_write_req *) data;
|
struct bt_att_write_req *req = (struct bt_att_write_req *)data;
|
||||||
|
|
||||||
bool with_response = (op == BT_ATT_OP_WRITE_REQ);
|
bool with_response = (op == BT_ATT_OP_WRITE_REQ);
|
||||||
|
|
||||||
@ -1397,7 +1396,7 @@ STATIC void process_write_req_or_cmd(uint16_t conn_handle, uint16_t mtu, uint8_t
|
|||||||
.code = BT_ATT_OP_WRITE_RSP,
|
.code = BT_ATT_OP_WRITE_RSP,
|
||||||
};
|
};
|
||||||
|
|
||||||
hci_send_acl_pkt(conn_handle, BT_L2CAP_CID_ATT, sizeof(rsp), (uint8_t *) &rsp);
|
hci_send_acl_pkt(conn_handle, BT_L2CAP_CID_ATT, sizeof(rsp), (uint8_t *)&rsp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1410,7 +1409,7 @@ STATIC void process_write_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_prepare_write_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_prepare_write_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
||||||
struct bt_att_prepare_write_req *req = (struct bt_att_prepare_write_req *) data;
|
struct bt_att_prepare_write_req *req = (struct bt_att_prepare_write_req *)data;
|
||||||
|
|
||||||
if (dlen < sizeof(struct bt_att_prepare_write_req)) {
|
if (dlen < sizeof(struct bt_att_prepare_write_req)) {
|
||||||
send_error(conn_handle, BT_ATT_OP_PREPARE_WRITE_REQ, BLE_GATT_HANDLE_INVALID, BT_ATT_ERR_INVALID_PDU);
|
send_error(conn_handle, BT_ATT_OP_PREPARE_WRITE_REQ, BLE_GATT_HANDLE_INVALID, BT_ATT_ERR_INVALID_PDU);
|
||||||
@ -1419,7 +1418,7 @@ STATIC void process_prepare_write_req(uint16_t conn_handle, uint16_t mtu, uint8_
|
|||||||
|
|
||||||
uint16_t handle = req->handle;
|
uint16_t handle = req->handle;
|
||||||
uint16_t offset = req->offset;
|
uint16_t offset = req->offset;
|
||||||
(void) offset;
|
(void)offset;
|
||||||
|
|
||||||
if (handle > bleio_adapter_max_attribute_handle(&common_hal_bleio_adapter_obj)) {
|
if (handle > bleio_adapter_max_attribute_handle(&common_hal_bleio_adapter_obj)) {
|
||||||
send_error(conn_handle, BT_ATT_OP_PREPARE_WRITE_REQ, handle, BT_ATT_ERR_ATTRIBUTE_NOT_FOUND);
|
send_error(conn_handle, BT_ATT_OP_PREPARE_WRITE_REQ, handle, BT_ATT_ERR_ATTRIBUTE_NOT_FOUND);
|
||||||
@ -1433,7 +1432,7 @@ STATIC void process_prepare_write_req(uint16_t conn_handle, uint16_t mtu, uint8_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bleio_characteristic_obj_t* characteristic = MP_OBJ_TO_PTR(attribute);
|
bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(attribute);
|
||||||
|
|
||||||
if (handle != characteristic->handle) {
|
if (handle != characteristic->handle) {
|
||||||
send_error(conn_handle, BT_ATT_OP_PREPARE_WRITE_REQ, handle, BT_ATT_ERR_ATTRIBUTE_NOT_LONG);
|
send_error(conn_handle, BT_ATT_OP_PREPARE_WRITE_REQ, handle, BT_ATT_ERR_ATTRIBUTE_NOT_LONG);
|
||||||
@ -1445,7 +1444,7 @@ STATIC void process_prepare_write_req(uint16_t conn_handle, uint16_t mtu, uint8_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIX if (long_write_handle == BLE_GATT_HANDLE_INVALID)
|
// FIX if (long_write_handle == BLE_GATT_HANDLE_INVALID)
|
||||||
// int valueSize = characteristic->valueSize();
|
// int valueSize = characteristic->valueSize();
|
||||||
|
|
||||||
// long_write_value = (uint8_t*)realloc(long_write_value, valueSize);
|
// long_write_value = (uint8_t*)realloc(long_write_value, valueSize);
|
||||||
@ -1480,7 +1479,7 @@ STATIC void process_prepare_write_req(uint16_t conn_handle, uint16_t mtu, uint8_
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_exec_write_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_exec_write_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
|
||||||
struct bt_att_exec_write_req *req = (struct bt_att_exec_write_req *) data;
|
struct bt_att_exec_write_req *req = (struct bt_att_exec_write_req *)data;
|
||||||
|
|
||||||
if (dlen != sizeof(struct bt_att_exec_write_req)) {
|
if (dlen != sizeof(struct bt_att_exec_write_req)) {
|
||||||
send_error(conn_handle, BT_ATT_OP_EXEC_WRITE_REQ, BLE_GATT_HANDLE_INVALID, BT_ATT_ERR_INVALID_PDU);
|
send_error(conn_handle, BT_ATT_OP_EXEC_WRITE_REQ, BLE_GATT_HANDLE_INVALID, BT_ATT_ERR_INVALID_PDU);
|
||||||
@ -1488,11 +1487,11 @@ STATIC void process_exec_write_req(uint16_t conn_handle, uint16_t mtu, uint8_t d
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (long_write_handle && (req->flags & 0x01)) {
|
if (long_write_handle && (req->flags & 0x01)) {
|
||||||
//FIX BLELocalCharacteristic* characteristic = (BLELocalCharacteristic*)GATT.attribute(long_write_handle - 1);
|
// FIX BLELocalCharacteristic* characteristic = (BLELocalCharacteristic*)GATT.attribute(long_write_handle - 1);
|
||||||
|
|
||||||
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
||||||
if (bleio_connections[i].conn_handle == conn_handle) {
|
if (bleio_connections[i].conn_handle == conn_handle) {
|
||||||
//FIX characteristic->writeValue(BLEDevice(bleio_connections[i].address_type, bleio_connections[i].address), long_write_value, long_write_value_length);
|
// FIX characteristic->writeValue(BLEDevice(bleio_connections[i].address_type, bleio_connections[i].address), long_write_value, long_write_value_length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1516,16 +1515,16 @@ STATIC void process_notify_or_indicate(uint16_t conn_handle, uint8_t opcode, uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// struct bt_att_notify and bt_att_indicate are identical.
|
// struct bt_att_notify and bt_att_indicate are identical.
|
||||||
//FIXunused struct bt_att_notify *req = (struct bt_att_notify *) data;
|
// FIXunused struct bt_att_notify *req = (struct bt_att_notify *) data;
|
||||||
|
|
||||||
//FIXunused uint8_t handle = req->handle;
|
// FIXunused uint8_t handle = req->handle;
|
||||||
|
|
||||||
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
||||||
if (bleio_connections[i].conn_handle != conn_handle) {
|
if (bleio_connections[i].conn_handle != conn_handle) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIX BLERemoteDevice* device = bleio_connections[i].device;
|
// FIX BLERemoteDevice* device = bleio_connections[i].device;
|
||||||
|
|
||||||
// if (!device) {
|
// if (!device) {
|
||||||
// break;
|
// break;
|
||||||
@ -1562,9 +1561,9 @@ STATIC void process_notify_or_indicate(uint16_t conn_handle, uint8_t opcode, uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_confirm(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
STATIC void process_confirm(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
||||||
(void) conn_handle;
|
(void)conn_handle;
|
||||||
(void) dlen;
|
(void)dlen;
|
||||||
(void) data;
|
(void)data;
|
||||||
|
|
||||||
confirm = true;
|
confirm = true;
|
||||||
}
|
}
|
||||||
@ -1574,7 +1573,7 @@ bool att_exchange_mtu(uint16_t conn_handle) {
|
|||||||
struct bt_att_exchange_mtu_req req = {
|
struct bt_att_exchange_mtu_req req = {
|
||||||
.mtu = max_mtu,
|
.mtu = max_mtu,
|
||||||
};
|
};
|
||||||
return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *) &req, response_buffer);
|
return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *)&req, response_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int att_read_req(uint16_t conn_handle, uint16_t handle, uint8_t response_buffer[]) {
|
int att_read_req(uint16_t conn_handle, uint16_t handle, uint8_t response_buffer[]) {
|
||||||
@ -1582,23 +1581,22 @@ int att_read_req(uint16_t conn_handle, uint16_t handle, uint8_t response_buffer[
|
|||||||
struct bt_att_hdr h;
|
struct bt_att_hdr h;
|
||||||
struct bt_att_read_req r;
|
struct bt_att_read_req r;
|
||||||
} req = { {
|
} req = { {
|
||||||
.code = BT_ATT_OP_READ_REQ,
|
.code = BT_ATT_OP_READ_REQ,
|
||||||
}, {
|
}, {
|
||||||
.handle = handle,
|
.handle = handle,
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
|
|
||||||
return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *) &req, response_buffer);
|
return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *)&req, response_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int att_write_req(uint16_t conn_handle, uint16_t handle, const uint8_t* data, uint8_t data_len, uint8_t response_buffer[]) {
|
int att_write_req(uint16_t conn_handle, uint16_t handle, const uint8_t *data, uint8_t data_len, uint8_t response_buffer[]) {
|
||||||
typedef struct __packed {
|
typedef struct __packed {
|
||||||
struct bt_att_hdr h;
|
struct bt_att_hdr h;
|
||||||
struct bt_att_write_req r;
|
struct bt_att_write_req r;
|
||||||
} req_t;
|
} req_t;
|
||||||
|
|
||||||
uint8_t req_bytes[sizeof(req_t) + data_len];
|
uint8_t req_bytes[sizeof(req_t) + data_len];
|
||||||
req_t *req = (req_t *) req_bytes;
|
req_t *req = (req_t *)req_bytes;
|
||||||
req->h.code = BT_ATT_OP_WRITE_REQ;
|
req->h.code = BT_ATT_OP_WRITE_REQ;
|
||||||
req->r.handle = handle;
|
req->r.handle = handle;
|
||||||
memcpy(req->r.value, data, data_len);
|
memcpy(req->r.value, data, data_len);
|
||||||
@ -1606,14 +1604,14 @@ int att_write_req(uint16_t conn_handle, uint16_t handle, const uint8_t* data, ui
|
|||||||
return send_req_wait_for_rsp(conn_handle, sizeof(req_bytes), req_bytes, response_buffer);
|
return send_req_wait_for_rsp(conn_handle, sizeof(req_bytes), req_bytes, response_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void att_write_cmd(uint16_t conn_handle, uint16_t handle, const uint8_t* data, uint8_t data_len) {
|
void att_write_cmd(uint16_t conn_handle, uint16_t handle, const uint8_t *data, uint8_t data_len) {
|
||||||
typedef struct __packed {
|
typedef struct __packed {
|
||||||
struct bt_att_hdr h;
|
struct bt_att_hdr h;
|
||||||
struct bt_att_write_cmd r;
|
struct bt_att_write_cmd r;
|
||||||
} cmd_t;
|
} cmd_t;
|
||||||
|
|
||||||
uint8_t cmd_bytes[sizeof(cmd_t) + data_len];
|
uint8_t cmd_bytes[sizeof(cmd_t) + data_len];
|
||||||
cmd_t *cmd = (cmd_t *) cmd_bytes;
|
cmd_t *cmd = (cmd_t *)cmd_bytes;
|
||||||
cmd->h.code = BT_ATT_OP_WRITE_CMD;
|
cmd->h.code = BT_ATT_OP_WRITE_CMD;
|
||||||
cmd->r.handle = handle;
|
cmd->r.handle = handle;
|
||||||
memcpy(cmd->r.value, data, data_len);
|
memcpy(cmd->r.value, data, data_len);
|
||||||
@ -1715,7 +1713,7 @@ void att_process_data(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIX Do we need all of these?
|
// FIX Do we need all of these?
|
||||||
void check_att_err(uint8_t err) {
|
void check_att_err(uint8_t err) {
|
||||||
const compressed_string_t *msg = NULL;
|
const compressed_string_t *msg = NULL;
|
||||||
switch (err) {
|
switch (err) {
|
||||||
|
@ -32,19 +32,19 @@
|
|||||||
|
|
||||||
void bleio_att_reset(void);
|
void bleio_att_reset(void);
|
||||||
|
|
||||||
//FIX void att_set_event_handler(BLEDeviceEvent event, BLEDeviceEventHandler eventHandler);
|
// FIX void att_set_event_handler(BLEDeviceEvent event, BLEDeviceEventHandler eventHandler);
|
||||||
bool att_address_is_connected(bt_addr_le_t *addr);
|
bool att_address_is_connected(bt_addr_le_t *addr);
|
||||||
bool att_connect_to_address(bt_addr_le_t *addr);
|
bool att_connect_to_address(bt_addr_le_t *addr);
|
||||||
bool att_disconnect(uint16_t conn_handle);
|
bool att_disconnect(uint16_t conn_handle);
|
||||||
bool att_disconnect_all(void);
|
bool att_disconnect_all(void);
|
||||||
bool att_discover_attributes(bt_addr_le_t *addr, const char* service_uuid_filter);
|
bool att_discover_attributes(bt_addr_le_t *addr, const char *service_uuid_filter);
|
||||||
bool att_exchange_mtu(uint16_t conn_handle);
|
bool att_exchange_mtu(uint16_t conn_handle);
|
||||||
bool att_handle_is_connected(uint16_t handle);
|
bool att_handle_is_connected(uint16_t handle);
|
||||||
bool att_indicate(uint16_t handle, const uint8_t* value, int length);
|
bool att_indicate(uint16_t handle, const uint8_t *value, int length);
|
||||||
bool att_is_connected(void);
|
bool att_is_connected(void);
|
||||||
bool att_notify(uint16_t handle, const uint8_t* value, int length);
|
bool att_notify(uint16_t handle, const uint8_t *value, int length);
|
||||||
int att_read_req(uint16_t conn_handle, uint16_t handle, uint8_t response_buffer[]);
|
int att_read_req(uint16_t conn_handle, uint16_t handle, uint8_t response_buffer[]);
|
||||||
int att_write_req(uint16_t conn_handle, uint16_t handle, const uint8_t* data, uint8_t data_len, uint8_t response_buffer[]);
|
int att_write_req(uint16_t conn_handle, uint16_t handle, const uint8_t *data, uint8_t data_len, uint8_t response_buffer[]);
|
||||||
uint16_t att_conn_handle(bt_addr_le_t *addr);
|
uint16_t att_conn_handle(bt_addr_le_t *addr);
|
||||||
uint16_t att_mtu(uint16_t handle);
|
uint16_t att_mtu(uint16_t handle);
|
||||||
void att_add_connection(uint16_t handle, uint8_t role, bt_addr_le_t *peer_addr, uint16_t interval, uint16_t latency, uint16_t supervision_timeout, uint8_t master_clock_accuracy);
|
void att_add_connection(uint16_t handle, uint8_t role, bt_addr_le_t *peer_addr, uint16_t interval, uint16_t latency, uint16_t supervision_timeout, uint8_t master_clock_accuracy);
|
||||||
@ -52,6 +52,6 @@ void att_process_data(uint16_t conn_handle, uint8_t dlen, uint8_t data[]);
|
|||||||
void att_remove_connection(uint16_t conn_handle, uint8_t reason);
|
void att_remove_connection(uint16_t conn_handle, uint8_t reason);
|
||||||
void att_set_max_mtu(uint16_t max_mtu);
|
void att_set_max_mtu(uint16_t max_mtu);
|
||||||
void att_set_timeout(unsigned long timeout);
|
void att_set_timeout(unsigned long timeout);
|
||||||
void att_write_cmd(uint16_t conn_handle, uint16_t handle, const uint8_t* data, uint8_t data_len);
|
void att_write_cmd(uint16_t conn_handle, uint16_t handle, const uint8_t *data, uint8_t data_len);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_ATT_H
|
#endif // MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_ATT_H
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "py/mphal.h" //*****************************
|
#include "py/mphal.h" // *****************************
|
||||||
#include "supervisor/shared/tick.h"
|
#include "supervisor/shared/tick.h"
|
||||||
#include "shared-bindings/_bleio/__init__.h"
|
#include "shared-bindings/_bleio/__init__.h"
|
||||||
#include "common-hal/_bleio/Adapter.h"
|
#include "common-hal/_bleio/Adapter.h"
|
||||||
@ -63,8 +63,8 @@ typedef struct __attribute__ ((packed)) {
|
|||||||
typedef struct __attribute__ ((packed)) {
|
typedef struct __attribute__ ((packed)) {
|
||||||
uint8_t pkt_type;
|
uint8_t pkt_type;
|
||||||
uint16_t handle : 12;
|
uint16_t handle : 12;
|
||||||
uint8_t pb: 2; // Packet boundary flag: ACL_DATA_PB values.
|
uint8_t pb : 2; // Packet boundary flag: ACL_DATA_PB values.
|
||||||
uint8_t bc: 2; // Broadcast flag: always 0b00 for BLE.
|
uint8_t bc : 2; // Broadcast flag: always 0b00 for BLE.
|
||||||
uint16_t data_len; // length of data[] in this packet.
|
uint16_t data_len; // length of data[] in this packet.
|
||||||
uint8_t data[];
|
uint8_t data[];
|
||||||
} h4_hci_acl_pkt_t;
|
} h4_hci_acl_pkt_t;
|
||||||
@ -89,7 +89,7 @@ typedef struct __attribute__ ((packed)) {
|
|||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Static storage:
|
// Static storage:
|
||||||
|
|
||||||
//FIX size
|
// FIX size
|
||||||
#define RX_BUFFER_SIZE (3 + 255)
|
#define RX_BUFFER_SIZE (3 + 255)
|
||||||
#define ACL_DATA_BUFFER_SIZE (255)
|
#define ACL_DATA_BUFFER_SIZE (255)
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ STATIC bool cmd_response_received;
|
|||||||
STATIC uint16_t cmd_response_opcode;
|
STATIC uint16_t cmd_response_opcode;
|
||||||
STATIC uint8_t cmd_response_status;
|
STATIC uint8_t cmd_response_status;
|
||||||
STATIC size_t cmd_response_len;
|
STATIC size_t cmd_response_len;
|
||||||
STATIC uint8_t* cmd_response_data;
|
STATIC uint8_t *cmd_response_data;
|
||||||
|
|
||||||
STATIC volatile bool hci_poll_in_progress = false;
|
STATIC volatile bool hci_poll_in_progress = false;
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ STATIC volatile bool hci_poll_in_progress = false;
|
|||||||
#endif // HCI_DEBUG
|
#endif // HCI_DEBUG
|
||||||
|
|
||||||
STATIC void process_acl_data_pkt(uint8_t pkt_len, uint8_t pkt_data[]) {
|
STATIC void process_acl_data_pkt(uint8_t pkt_len, uint8_t pkt_data[]) {
|
||||||
h4_hci_acl_pkt_t *pkt = (h4_hci_acl_pkt_t*) pkt_data;
|
h4_hci_acl_pkt_t *pkt = (h4_hci_acl_pkt_t *)pkt_data;
|
||||||
|
|
||||||
if (pkt->pb != ACL_DATA_PB_MIDDLE) {
|
if (pkt->pb != ACL_DATA_PB_MIDDLE) {
|
||||||
// This is the start of a fragmented acl_data packet or is a full packet.
|
// This is the start of a fragmented acl_data packet or is a full packet.
|
||||||
@ -132,7 +132,7 @@ STATIC void process_acl_data_pkt(uint8_t pkt_len, uint8_t pkt_data[]) {
|
|||||||
acl_data_len += pkt->data_len;
|
acl_data_len += pkt->data_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
acl_data_t *acl = (acl_data_t *) &acl_data_buffer;
|
acl_data_t *acl = (acl_data_t *)&acl_data_buffer;
|
||||||
if (acl_data_len != sizeof(acl) + acl->acl_data_len) {
|
if (acl_data_len != sizeof(acl) + acl->acl_data_len) {
|
||||||
// We don't have the full packet yet.
|
// We don't have the full packet yet.
|
||||||
return;
|
return;
|
||||||
@ -167,18 +167,17 @@ STATIC void process_num_comp_pkts(uint16_t handle, uint16_t num_pkts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void process_evt_pkt(size_t pkt_len, uint8_t pkt_data[])
|
STATIC void process_evt_pkt(size_t pkt_len, uint8_t pkt_data[]) {
|
||||||
{
|
h4_hci_evt_pkt_t *pkt = (h4_hci_evt_pkt_t *)pkt_data;
|
||||||
h4_hci_evt_pkt_t *pkt = (h4_hci_evt_pkt_t*) pkt_data;
|
|
||||||
|
|
||||||
switch (pkt->evt) {
|
switch (pkt->evt) {
|
||||||
case BT_HCI_EVT_DISCONN_COMPLETE: {
|
case BT_HCI_EVT_DISCONN_COMPLETE: {
|
||||||
struct bt_hci_evt_disconn_complete *disconn_complete =
|
struct bt_hci_evt_disconn_complete *disconn_complete =
|
||||||
(struct bt_hci_evt_disconn_complete*) pkt->params;
|
(struct bt_hci_evt_disconn_complete *)pkt->params;
|
||||||
(void) disconn_complete;
|
(void)disconn_complete;
|
||||||
|
|
||||||
att_remove_connection(disconn_complete->handle, disconn_complete->reason);
|
att_remove_connection(disconn_complete->handle, disconn_complete->reason);
|
||||||
//FIX L2CAPSignaling.removeConnection(disconn_complete->handle, disconn_complete->reason);
|
// FIX L2CAPSignaling.removeConnection(disconn_complete->handle, disconn_complete->reason);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +187,7 @@ STATIC void process_evt_pkt(size_t pkt_len, uint8_t pkt_data[])
|
|||||||
struct bt_hci_evt_cc_status cc_status;
|
struct bt_hci_evt_cc_status cc_status;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct cmd_complete_with_status *evt = (struct cmd_complete_with_status *) pkt->params;
|
struct cmd_complete_with_status *evt = (struct cmd_complete_with_status *)pkt->params;
|
||||||
|
|
||||||
num_command_packets_allowed = evt->cmd_complete.ncmd;
|
num_command_packets_allowed = evt->cmd_complete.ncmd;
|
||||||
|
|
||||||
@ -197,7 +196,7 @@ STATIC void process_evt_pkt(size_t pkt_len, uint8_t pkt_data[])
|
|||||||
cmd_response_status = evt->cc_status.status;
|
cmd_response_status = evt->cc_status.status;
|
||||||
// All the bytes following cmd_complete, -including- the status byte, which is
|
// All the bytes following cmd_complete, -including- the status byte, which is
|
||||||
// included in all the _bt_hci_rp_* structs.
|
// included in all the _bt_hci_rp_* structs.
|
||||||
cmd_response_data = (uint8_t *) &evt->cc_status;
|
cmd_response_data = (uint8_t *)&evt->cc_status;
|
||||||
// Includes status byte.
|
// Includes status byte.
|
||||||
cmd_response_len = pkt->param_len - sizeof_field(struct cmd_complete_with_status, cmd_complete);
|
cmd_response_len = pkt->param_len - sizeof_field(struct cmd_complete_with_status, cmd_complete);
|
||||||
|
|
||||||
@ -205,7 +204,7 @@ STATIC void process_evt_pkt(size_t pkt_len, uint8_t pkt_data[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
case BT_HCI_EVT_CMD_STATUS: {
|
case BT_HCI_EVT_CMD_STATUS: {
|
||||||
struct bt_hci_evt_cmd_status *evt = (struct bt_hci_evt_cmd_status *) pkt->params;
|
struct bt_hci_evt_cmd_status *evt = (struct bt_hci_evt_cmd_status *)pkt->params;
|
||||||
|
|
||||||
num_command_packets_allowed = evt->ncmd;
|
num_command_packets_allowed = evt->ncmd;
|
||||||
|
|
||||||
@ -220,7 +219,7 @@ STATIC void process_evt_pkt(size_t pkt_len, uint8_t pkt_data[])
|
|||||||
|
|
||||||
case BT_HCI_EVT_NUM_COMPLETED_PACKETS: {
|
case BT_HCI_EVT_NUM_COMPLETED_PACKETS: {
|
||||||
struct bt_hci_evt_num_completed_packets *evt =
|
struct bt_hci_evt_num_completed_packets *evt =
|
||||||
(struct bt_hci_evt_num_completed_packets *) pkt->params;
|
(struct bt_hci_evt_num_completed_packets *)pkt->params;
|
||||||
|
|
||||||
// Start at zero-th pair: (conn handle, num completed packets).
|
// Start at zero-th pair: (conn handle, num completed packets).
|
||||||
struct bt_hci_handle_count *handle_and_count = &(evt->h[0]);
|
struct bt_hci_handle_count *handle_and_count = &(evt->h[0]);
|
||||||
@ -232,8 +231,8 @@ STATIC void process_evt_pkt(size_t pkt_len, uint8_t pkt_data[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
case BT_HCI_EVT_LE_META_EVENT: {
|
case BT_HCI_EVT_LE_META_EVENT: {
|
||||||
struct bt_hci_evt_le_meta_event *meta_evt = (struct bt_hci_evt_le_meta_event *) pkt->params;
|
struct bt_hci_evt_le_meta_event *meta_evt = (struct bt_hci_evt_le_meta_event *)pkt->params;
|
||||||
uint8_t *le_evt = pkt->params + sizeof (struct bt_hci_evt_le_meta_event);
|
uint8_t *le_evt = pkt->params + sizeof (struct bt_hci_evt_le_meta_event);
|
||||||
|
|
||||||
if (meta_evt->subevent == BT_HCI_EVT_LE_CONN_COMPLETE) {
|
if (meta_evt->subevent == BT_HCI_EVT_LE_CONN_COMPLETE) {
|
||||||
// Advertising stops when connection occurs.
|
// Advertising stops when connection occurs.
|
||||||
@ -243,7 +242,7 @@ STATIC void process_evt_pkt(size_t pkt_len, uint8_t pkt_data[])
|
|||||||
bleio_adapter_advertising_was_stopped(&common_hal_bleio_adapter_obj);
|
bleio_adapter_advertising_was_stopped(&common_hal_bleio_adapter_obj);
|
||||||
|
|
||||||
struct bt_hci_evt_le_conn_complete *le_conn_complete =
|
struct bt_hci_evt_le_conn_complete *le_conn_complete =
|
||||||
(struct bt_hci_evt_le_conn_complete *) le_evt;
|
(struct bt_hci_evt_le_conn_complete *)le_evt;
|
||||||
|
|
||||||
if (le_conn_complete->status == BT_HCI_ERR_SUCCESS) {
|
if (le_conn_complete->status == BT_HCI_ERR_SUCCESS) {
|
||||||
att_add_connection(
|
att_add_connection(
|
||||||
@ -258,9 +257,9 @@ STATIC void process_evt_pkt(size_t pkt_len, uint8_t pkt_data[])
|
|||||||
}
|
}
|
||||||
} else if (meta_evt->subevent == BT_HCI_EVT_LE_ADVERTISING_REPORT) {
|
} else if (meta_evt->subevent == BT_HCI_EVT_LE_ADVERTISING_REPORT) {
|
||||||
struct bt_hci_evt_le_advertising_info *le_advertising_info =
|
struct bt_hci_evt_le_advertising_info *le_advertising_info =
|
||||||
(struct bt_hci_evt_le_advertising_info *) le_evt;
|
(struct bt_hci_evt_le_advertising_info *)le_evt;
|
||||||
if (le_advertising_info->evt_type == BT_HCI_ADV_DIRECT_IND) {
|
if (le_advertising_info->evt_type == BT_HCI_ADV_DIRECT_IND) {
|
||||||
//FIX
|
// FIX
|
||||||
// last byte is RSSI
|
// last byte is RSSI
|
||||||
// GAP.handleLeAdvertisingReport(leAdvertisingReport->type,
|
// GAP.handleLeAdvertisingReport(leAdvertisingReport->type,
|
||||||
// leAdvertisingReport->peerBdaddrType,
|
// leAdvertisingReport->peerBdaddrType,
|
||||||
@ -275,9 +274,9 @@ STATIC void process_evt_pkt(size_t pkt_len, uint8_t pkt_data[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
#if HCI_DEBUG
|
#if HCI_DEBUG
|
||||||
mp_printf(&mp_plat_print, "process_evt_pkt: Unknown event: %02x\n");
|
mp_printf(&mp_plat_print, "process_evt_pkt: Unknown event: %02x\n");
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,7 +332,7 @@ hci_result_t hci_poll_for_incoming_pkt(void) {
|
|||||||
case H4_ACL:
|
case H4_ACL:
|
||||||
if (rx_idx >= sizeof(h4_hci_acl_pkt_t)) {
|
if (rx_idx >= sizeof(h4_hci_acl_pkt_t)) {
|
||||||
const size_t total_len =
|
const size_t total_len =
|
||||||
sizeof(h4_hci_acl_pkt_t) + ((h4_hci_acl_pkt_t *) rx_buffer)->data_len;
|
sizeof(h4_hci_acl_pkt_t) + ((h4_hci_acl_pkt_t *)rx_buffer)->data_len;
|
||||||
if (rx_idx == total_len) {
|
if (rx_idx == total_len) {
|
||||||
packet_is_complete = true;
|
packet_is_complete = true;
|
||||||
}
|
}
|
||||||
@ -346,7 +345,7 @@ hci_result_t hci_poll_for_incoming_pkt(void) {
|
|||||||
case H4_EVT:
|
case H4_EVT:
|
||||||
if (rx_idx >= sizeof(h4_hci_evt_pkt_t)) {
|
if (rx_idx >= sizeof(h4_hci_evt_pkt_t)) {
|
||||||
const size_t total_len =
|
const size_t total_len =
|
||||||
sizeof(h4_hci_evt_pkt_t) + ((h4_hci_evt_pkt_t *) rx_buffer)->param_len;
|
sizeof(h4_hci_evt_pkt_t) + ((h4_hci_evt_pkt_t *)rx_buffer)->param_len;
|
||||||
if (rx_idx == total_len) {
|
if (rx_idx == total_len) {
|
||||||
packet_is_complete = true;
|
packet_is_complete = true;
|
||||||
}
|
}
|
||||||
@ -374,23 +373,23 @@ hci_result_t hci_poll_for_incoming_pkt(void) {
|
|||||||
|
|
||||||
switch (rx_buffer[0]) {
|
switch (rx_buffer[0]) {
|
||||||
case H4_ACL:
|
case H4_ACL:
|
||||||
#if HCI_DEBUG
|
#if HCI_DEBUG
|
||||||
dump_acl_pkt(false, pkt_len, rx_buffer);
|
dump_acl_pkt(false, pkt_len, rx_buffer);
|
||||||
#endif
|
#endif
|
||||||
process_acl_data_pkt(pkt_len, rx_buffer);
|
process_acl_data_pkt(pkt_len, rx_buffer);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case H4_EVT:
|
case H4_EVT:
|
||||||
#if HCI_DEBUG
|
#if HCI_DEBUG
|
||||||
dump_evt_pkt(false, pkt_len, rx_buffer);
|
dump_evt_pkt(false, pkt_len, rx_buffer);
|
||||||
#endif
|
#endif
|
||||||
process_evt_pkt(pkt_len, rx_buffer);
|
process_evt_pkt(pkt_len, rx_buffer);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
#if HCI_DEBUG
|
#if HCI_DEBUG
|
||||||
mp_printf(&mp_plat_print, "Unknown HCI packet type: %d\n", rx_buffer[0]);
|
mp_printf(&mp_plat_print, "Unknown HCI packet type: %d\n", rx_buffer[0]);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,21 +424,21 @@ STATIC hci_result_t write_pkt(uint8_t *buffer, size_t len) {
|
|||||||
return HCI_OK;
|
return HCI_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC hci_result_t send_command(uint16_t opcode, uint8_t params_len, void* params) {
|
STATIC hci_result_t send_command(uint16_t opcode, uint8_t params_len, void *params) {
|
||||||
uint8_t cmd_pkt_len = sizeof(h4_hci_cmd_pkt_t) + params_len;
|
uint8_t cmd_pkt_len = sizeof(h4_hci_cmd_pkt_t) + params_len;
|
||||||
uint8_t tx_buffer[cmd_pkt_len];
|
uint8_t tx_buffer[cmd_pkt_len];
|
||||||
|
|
||||||
// cmd header is at the beginning of tx_buffer
|
// cmd header is at the beginning of tx_buffer
|
||||||
h4_hci_cmd_pkt_t *cmd_pkt = (h4_hci_cmd_pkt_t *) tx_buffer;
|
h4_hci_cmd_pkt_t *cmd_pkt = (h4_hci_cmd_pkt_t *)tx_buffer;
|
||||||
cmd_pkt->pkt_type = H4_CMD;
|
cmd_pkt->pkt_type = H4_CMD;
|
||||||
cmd_pkt->opcode = opcode;
|
cmd_pkt->opcode = opcode;
|
||||||
cmd_pkt->param_len = params_len;
|
cmd_pkt->param_len = params_len;
|
||||||
|
|
||||||
memcpy(cmd_pkt->params, params, params_len);
|
memcpy(cmd_pkt->params, params, params_len);
|
||||||
|
|
||||||
#if HCI_DEBUG
|
#if HCI_DEBUG
|
||||||
dump_cmd_pkt(true, sizeof(tx_buffer), tx_buffer);
|
dump_cmd_pkt(true, sizeof(tx_buffer), tx_buffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int result = write_pkt(tx_buffer, cmd_pkt_len);
|
int result = write_pkt(tx_buffer, cmd_pkt_len);
|
||||||
if (result != HCI_OK) {
|
if (result != HCI_OK) {
|
||||||
@ -478,8 +477,8 @@ hci_result_t hci_send_acl_pkt(uint16_t handle, uint8_t cid, uint16_t data_len, u
|
|||||||
const size_t buf_len = sizeof(h4_hci_acl_pkt_t) + sizeof(acl_data_t) + data_len;
|
const size_t buf_len = sizeof(h4_hci_acl_pkt_t) + sizeof(acl_data_t) + data_len;
|
||||||
uint8_t tx_buffer[buf_len];
|
uint8_t tx_buffer[buf_len];
|
||||||
|
|
||||||
h4_hci_acl_pkt_t *acl_pkt = (h4_hci_acl_pkt_t *) tx_buffer;
|
h4_hci_acl_pkt_t *acl_pkt = (h4_hci_acl_pkt_t *)tx_buffer;
|
||||||
acl_data_t *acl_data = (acl_data_t *) acl_pkt->data;
|
acl_data_t *acl_data = (acl_data_t *)acl_pkt->data;
|
||||||
acl_pkt->pkt_type = H4_ACL;
|
acl_pkt->pkt_type = H4_ACL;
|
||||||
acl_pkt->handle = handle;
|
acl_pkt->handle = handle;
|
||||||
acl_pkt->pb = ACL_DATA_PB_FIRST_FLUSH;
|
acl_pkt->pb = ACL_DATA_PB_FIRST_FLUSH;
|
||||||
@ -490,9 +489,9 @@ hci_result_t hci_send_acl_pkt(uint16_t handle, uint8_t cid, uint16_t data_len, u
|
|||||||
|
|
||||||
memcpy(&acl_data->acl_data, data, data_len);
|
memcpy(&acl_data->acl_data, data, data_len);
|
||||||
|
|
||||||
#if HCI_DEBUG
|
#if HCI_DEBUG
|
||||||
dump_acl_pkt(true, buf_len, tx_buffer);
|
dump_acl_pkt(true, buf_len, tx_buffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pending_pkt++;
|
pending_pkt++;
|
||||||
|
|
||||||
@ -512,7 +511,7 @@ hci_result_t hci_read_local_version(uint8_t *hci_version, uint16_t *hci_revision
|
|||||||
hci_result_t result = send_command(BT_HCI_OP_READ_LOCAL_VERSION_INFO, 0, NULL);
|
hci_result_t result = send_command(BT_HCI_OP_READ_LOCAL_VERSION_INFO, 0, NULL);
|
||||||
if (result == HCI_OK) {
|
if (result == HCI_OK) {
|
||||||
struct bt_hci_rp_read_local_version_info *response =
|
struct bt_hci_rp_read_local_version_info *response =
|
||||||
(struct bt_hci_rp_read_local_version_info *) cmd_response_data;
|
(struct bt_hci_rp_read_local_version_info *)cmd_response_data;
|
||||||
*hci_version = response->hci_version;
|
*hci_version = response->hci_version;
|
||||||
*hci_revision = response->hci_revision;
|
*hci_revision = response->hci_revision;
|
||||||
*lmp_version = response->lmp_version;
|
*lmp_version = response->lmp_version;
|
||||||
@ -526,7 +525,7 @@ hci_result_t hci_read_local_version(uint8_t *hci_version, uint16_t *hci_revision
|
|||||||
hci_result_t hci_read_bd_addr(bt_addr_t *addr) {
|
hci_result_t hci_read_bd_addr(bt_addr_t *addr) {
|
||||||
int result = send_command(BT_HCI_OP_READ_BD_ADDR, 0, NULL);
|
int result = send_command(BT_HCI_OP_READ_BD_ADDR, 0, NULL);
|
||||||
if (result == HCI_OK) {
|
if (result == HCI_OK) {
|
||||||
struct bt_hci_rp_read_bd_addr *response = (struct bt_hci_rp_read_bd_addr *) cmd_response_data;
|
struct bt_hci_rp_read_bd_addr *response = (struct bt_hci_rp_read_bd_addr *)cmd_response_data;
|
||||||
memcpy(addr->val, response->bdaddr.val, sizeof_field(bt_addr_t, val));
|
memcpy(addr->val, response->bdaddr.val, sizeof_field(bt_addr_t, val));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,7 +535,7 @@ hci_result_t hci_read_bd_addr(bt_addr_t *addr) {
|
|||||||
hci_result_t hci_read_rssi(uint16_t handle, int *rssi) {
|
hci_result_t hci_read_rssi(uint16_t handle, int *rssi) {
|
||||||
int result = send_command(BT_HCI_OP_READ_RSSI, sizeof(handle), &handle);
|
int result = send_command(BT_HCI_OP_READ_RSSI, sizeof(handle), &handle);
|
||||||
if (result == HCI_OK) {
|
if (result == HCI_OK) {
|
||||||
struct bt_hci_rp_read_rssi *response = (struct bt_hci_rp_read_rssi *) cmd_response_data;
|
struct bt_hci_rp_read_rssi *response = (struct bt_hci_rp_read_rssi *)cmd_response_data;
|
||||||
*rssi = response->rssi;
|
*rssi = response->rssi;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,7 +550,7 @@ hci_result_t hci_le_read_buffer_size(uint16_t *le_max_len, uint8_t *le_max_num)
|
|||||||
int result = send_command(BT_HCI_OP_LE_READ_BUFFER_SIZE, 0, NULL);
|
int result = send_command(BT_HCI_OP_LE_READ_BUFFER_SIZE, 0, NULL);
|
||||||
if (result == HCI_OK) {
|
if (result == HCI_OK) {
|
||||||
struct bt_hci_rp_le_read_buffer_size *response =
|
struct bt_hci_rp_le_read_buffer_size *response =
|
||||||
(struct bt_hci_rp_le_read_buffer_size *) cmd_response_data;
|
(struct bt_hci_rp_le_read_buffer_size *)cmd_response_data;
|
||||||
*le_max_len = response->le_max_len;
|
*le_max_len = response->le_max_len;
|
||||||
*le_max_num = response->le_max_num;
|
*le_max_num = response->le_max_num;
|
||||||
}
|
}
|
||||||
@ -563,7 +562,7 @@ hci_result_t hci_read_buffer_size(uint16_t *acl_max_len, uint8_t *sco_max_len, u
|
|||||||
int result = send_command(BT_HCI_OP_READ_BUFFER_SIZE, 0, NULL);
|
int result = send_command(BT_HCI_OP_READ_BUFFER_SIZE, 0, NULL);
|
||||||
if (result == HCI_OK) {
|
if (result == HCI_OK) {
|
||||||
struct bt_hci_rp_read_buffer_size *response =
|
struct bt_hci_rp_read_buffer_size *response =
|
||||||
(struct bt_hci_rp_read_buffer_size *) cmd_response_data;
|
(struct bt_hci_rp_read_buffer_size *)cmd_response_data;
|
||||||
*acl_max_len = response->acl_max_len;
|
*acl_max_len = response->acl_max_len;
|
||||||
*sco_max_len = response->sco_max_len;
|
*sco_max_len = response->sco_max_len;
|
||||||
*acl_max_num = response->acl_max_num;
|
*acl_max_num = response->acl_max_num;
|
||||||
@ -608,10 +607,10 @@ hci_result_t hci_le_set_extended_advertising_parameters(uint8_t handle, uint16_t
|
|||||||
.scan_req_notify_enable = scan_req_notify_enable,
|
.scan_req_notify_enable = scan_req_notify_enable,
|
||||||
};
|
};
|
||||||
// Assumes little-endian.
|
// Assumes little-endian.
|
||||||
memcpy(params.prim_min_interval, (void *) &prim_min_interval,
|
memcpy(params.prim_min_interval, (void *)&prim_min_interval,
|
||||||
sizeof_field(struct bt_hci_cp_le_set_ext_adv_param, prim_min_interval));
|
sizeof_field(struct bt_hci_cp_le_set_ext_adv_param, prim_min_interval));
|
||||||
memcpy(params.prim_max_interval, (void *) &prim_max_interval,
|
memcpy(params.prim_max_interval, (void *)&prim_max_interval,
|
||||||
sizeof_field(struct bt_hci_cp_le_set_ext_adv_param, prim_max_interval));
|
sizeof_field(struct bt_hci_cp_le_set_ext_adv_param, prim_max_interval));
|
||||||
memcpy(params.peer_addr.a.val, peer_addr->a.val, sizeof_field(bt_addr_le_t, a.val));
|
memcpy(params.peer_addr.a.val, peer_addr->a.val, sizeof_field(bt_addr_le_t, a.val));
|
||||||
return send_command(BT_HCI_OP_LE_SET_EXT_ADV_PARAM, sizeof(params), ¶ms);
|
return send_command(BT_HCI_OP_LE_SET_EXT_ADV_PARAM, sizeof(params), ¶ms);
|
||||||
}
|
}
|
||||||
@ -620,7 +619,7 @@ hci_result_t hci_le_read_maximum_advertising_data_length(uint16_t *max_adv_data_
|
|||||||
int result = send_command(BT_HCI_OP_LE_READ_MAX_ADV_DATA_LEN, 0, NULL);
|
int result = send_command(BT_HCI_OP_LE_READ_MAX_ADV_DATA_LEN, 0, NULL);
|
||||||
if (result == HCI_OK) {
|
if (result == HCI_OK) {
|
||||||
struct bt_hci_rp_le_read_max_adv_data_len *response =
|
struct bt_hci_rp_le_read_max_adv_data_len *response =
|
||||||
(struct bt_hci_rp_le_read_max_adv_data_len *) cmd_response_data;
|
(struct bt_hci_rp_le_read_max_adv_data_len *)cmd_response_data;
|
||||||
*max_adv_data_len = response->max_adv_data_len;
|
*max_adv_data_len = response->max_adv_data_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,9 +630,9 @@ hci_result_t hci_le_read_local_supported_features(uint8_t features[8]) {
|
|||||||
int result = send_command(BT_HCI_OP_LE_READ_LOCAL_FEATURES, 0, NULL);
|
int result = send_command(BT_HCI_OP_LE_READ_LOCAL_FEATURES, 0, NULL);
|
||||||
if (result == HCI_OK) {
|
if (result == HCI_OK) {
|
||||||
struct bt_hci_rp_le_read_local_features *response =
|
struct bt_hci_rp_le_read_local_features *response =
|
||||||
(struct bt_hci_rp_le_read_local_features *) cmd_response_data;
|
(struct bt_hci_rp_le_read_local_features *)cmd_response_data;
|
||||||
memcpy(features, response->features,
|
memcpy(features, response->features,
|
||||||
sizeof_field(struct bt_hci_rp_le_read_local_features, features));
|
sizeof_field(struct bt_hci_rp_le_read_local_features, features));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -685,7 +684,7 @@ hci_result_t hci_le_set_advertising_enable(uint8_t enable) {
|
|||||||
hci_result_t hci_le_set_extended_advertising_enable(uint8_t enable, uint8_t set_num, uint8_t handle[], uint16_t duration[], uint8_t max_ext_adv_evts[]) {
|
hci_result_t hci_le_set_extended_advertising_enable(uint8_t enable, uint8_t set_num, uint8_t handle[], uint16_t duration[], uint8_t max_ext_adv_evts[]) {
|
||||||
uint8_t params[sizeof(struct bt_hci_cp_le_set_ext_adv_enable) +
|
uint8_t params[sizeof(struct bt_hci_cp_le_set_ext_adv_enable) +
|
||||||
set_num * (sizeof(struct bt_hci_ext_adv_set))];
|
set_num * (sizeof(struct bt_hci_ext_adv_set))];
|
||||||
struct bt_hci_cp_le_set_ext_adv_enable *params_p = (struct bt_hci_cp_le_set_ext_adv_enable *) ¶ms;
|
struct bt_hci_cp_le_set_ext_adv_enable *params_p = (struct bt_hci_cp_le_set_ext_adv_enable *)¶ms;
|
||||||
params_p->enable = enable;
|
params_p->enable = enable;
|
||||||
params_p->set_num = set_num;
|
params_p->set_num = set_num;
|
||||||
for (size_t i = 0; i < set_num; i++) {
|
for (size_t i = 0; i < set_num; i++) {
|
||||||
|
@ -26,248 +26,462 @@
|
|||||||
|
|
||||||
// This file is #include'd in hci.c when HCI_DEBUG is non-zero.
|
// This file is #include'd in hci.c when HCI_DEBUG is non-zero.
|
||||||
|
|
||||||
STATIC const char* att_opcode_name(uint16_t opcode) {
|
STATIC const char *att_opcode_name(uint16_t opcode) {
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case BT_ATT_OP_ERROR_RSP: return "ERROR_RSP";
|
case BT_ATT_OP_ERROR_RSP:
|
||||||
case BT_ATT_OP_MTU_REQ: return "MTU_REQ";
|
return "ERROR_RSP";
|
||||||
case BT_ATT_OP_MTU_RSP: return "MTU_RSP";
|
case BT_ATT_OP_MTU_REQ:
|
||||||
case BT_ATT_OP_FIND_INFO_REQ: return "FIND_INFO_REQ";
|
return "MTU_REQ";
|
||||||
case BT_ATT_OP_FIND_INFO_RSP: return "FIND_INFO_RSP";
|
case BT_ATT_OP_MTU_RSP:
|
||||||
case BT_ATT_OP_FIND_TYPE_REQ: return "FIND_TYPE_REQ";
|
return "MTU_RSP";
|
||||||
case BT_ATT_OP_FIND_TYPE_RSP: return "FIND_TYPE_RSP";
|
case BT_ATT_OP_FIND_INFO_REQ:
|
||||||
case BT_ATT_OP_READ_TYPE_REQ: return "READ_TYPE_REQ";
|
return "FIND_INFO_REQ";
|
||||||
case BT_ATT_OP_READ_TYPE_RSP: return "READ_TYPE_RSP";
|
case BT_ATT_OP_FIND_INFO_RSP:
|
||||||
case BT_ATT_OP_READ_REQ: return "READ_REQ";
|
return "FIND_INFO_RSP";
|
||||||
case BT_ATT_OP_READ_RSP: return "READ_RSP";
|
case BT_ATT_OP_FIND_TYPE_REQ:
|
||||||
case BT_ATT_OP_READ_BLOB_REQ: return "READ_BLOB_REQ";
|
return "FIND_TYPE_REQ";
|
||||||
case BT_ATT_OP_READ_BLOB_RSP: return "READ_BLOB_RSP";
|
case BT_ATT_OP_FIND_TYPE_RSP:
|
||||||
case BT_ATT_OP_READ_MULT_REQ: return "READ_MULT_REQ";
|
return "FIND_TYPE_RSP";
|
||||||
case BT_ATT_OP_READ_MULT_RSP: return "READ_MULT_RSP";
|
case BT_ATT_OP_READ_TYPE_REQ:
|
||||||
case BT_ATT_OP_READ_GROUP_REQ: return "READ_GROUP_REQ";
|
return "READ_TYPE_REQ";
|
||||||
case BT_ATT_OP_READ_GROUP_RSP: return "READ_GROUP_RSP";
|
case BT_ATT_OP_READ_TYPE_RSP:
|
||||||
case BT_ATT_OP_WRITE_REQ: return "WRITE_REQ";
|
return "READ_TYPE_RSP";
|
||||||
case BT_ATT_OP_WRITE_RSP: return "WRITE_RSP";
|
case BT_ATT_OP_READ_REQ:
|
||||||
case BT_ATT_OP_PREPARE_WRITE_REQ: return "PREPARE_WRITE_REQ";
|
return "READ_REQ";
|
||||||
case BT_ATT_OP_PREPARE_WRITE_RSP: return "PREPARE_WRITE_RSP";
|
case BT_ATT_OP_READ_RSP:
|
||||||
case BT_ATT_OP_EXEC_WRITE_REQ: return "EXEC_WRITE_REQ";
|
return "READ_RSP";
|
||||||
case BT_ATT_OP_EXEC_WRITE_RSP: return "EXEC_WRITE_RSP";
|
case BT_ATT_OP_READ_BLOB_REQ:
|
||||||
case BT_ATT_OP_NOTIFY: return "NOTIFY";
|
return "READ_BLOB_REQ";
|
||||||
case BT_ATT_OP_INDICATE: return "INDICATE";
|
case BT_ATT_OP_READ_BLOB_RSP:
|
||||||
case BT_ATT_OP_CONFIRM: return "CONFIRM";
|
return "READ_BLOB_RSP";
|
||||||
case BT_ATT_OP_READ_MULT_VL_REQ: return "READ_MULT_VL_REQ";
|
case BT_ATT_OP_READ_MULT_REQ:
|
||||||
case BT_ATT_OP_READ_MULT_VL_RSP: return "READ_MULT_VL_RSP";
|
return "READ_MULT_REQ";
|
||||||
case BT_ATT_OP_NOTIFY_MULT: return "NOTIFY_MULT";
|
case BT_ATT_OP_READ_MULT_RSP:
|
||||||
case BT_ATT_OP_WRITE_CMD: return "WRITE_CMD";
|
return "READ_MULT_RSP";
|
||||||
case BT_ATT_OP_SIGNED_WRITE_CMD: return "SIGNED_WRITE_CMD";
|
case BT_ATT_OP_READ_GROUP_REQ:
|
||||||
default: return "";
|
return "READ_GROUP_REQ";
|
||||||
|
case BT_ATT_OP_READ_GROUP_RSP:
|
||||||
|
return "READ_GROUP_RSP";
|
||||||
|
case BT_ATT_OP_WRITE_REQ:
|
||||||
|
return "WRITE_REQ";
|
||||||
|
case BT_ATT_OP_WRITE_RSP:
|
||||||
|
return "WRITE_RSP";
|
||||||
|
case BT_ATT_OP_PREPARE_WRITE_REQ:
|
||||||
|
return "PREPARE_WRITE_REQ";
|
||||||
|
case BT_ATT_OP_PREPARE_WRITE_RSP:
|
||||||
|
return "PREPARE_WRITE_RSP";
|
||||||
|
case BT_ATT_OP_EXEC_WRITE_REQ:
|
||||||
|
return "EXEC_WRITE_REQ";
|
||||||
|
case BT_ATT_OP_EXEC_WRITE_RSP:
|
||||||
|
return "EXEC_WRITE_RSP";
|
||||||
|
case BT_ATT_OP_NOTIFY:
|
||||||
|
return "NOTIFY";
|
||||||
|
case BT_ATT_OP_INDICATE:
|
||||||
|
return "INDICATE";
|
||||||
|
case BT_ATT_OP_CONFIRM:
|
||||||
|
return "CONFIRM";
|
||||||
|
case BT_ATT_OP_READ_MULT_VL_REQ:
|
||||||
|
return "READ_MULT_VL_REQ";
|
||||||
|
case BT_ATT_OP_READ_MULT_VL_RSP:
|
||||||
|
return "READ_MULT_VL_RSP";
|
||||||
|
case BT_ATT_OP_NOTIFY_MULT:
|
||||||
|
return "NOTIFY_MULT";
|
||||||
|
case BT_ATT_OP_WRITE_CMD:
|
||||||
|
return "WRITE_CMD";
|
||||||
|
case BT_ATT_OP_SIGNED_WRITE_CMD:
|
||||||
|
return "SIGNED_WRITE_CMD";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC const char* hci_evt_name(uint8_t evt) {
|
STATIC const char *hci_evt_name(uint8_t evt) {
|
||||||
switch (evt) {
|
switch (evt) {
|
||||||
case BT_HCI_EVT_UNKNOWN: return "UNKNOWN";
|
case BT_HCI_EVT_UNKNOWN:
|
||||||
case BT_HCI_EVT_VENDOR: return "VENDOR";
|
return "UNKNOWN";
|
||||||
case BT_HCI_EVT_INQUIRY_COMPLETE: return "INQUIRY_COMPLETE";
|
case BT_HCI_EVT_VENDOR:
|
||||||
case BT_HCI_EVT_CONN_COMPLETE: return "CONN_COMPLETE";
|
return "VENDOR";
|
||||||
case BT_HCI_EVT_CONN_REQUEST: return "CONN_REQUEST";
|
case BT_HCI_EVT_INQUIRY_COMPLETE:
|
||||||
case BT_HCI_EVT_DISCONN_COMPLETE: return "DISCONN_COMPLETE";
|
return "INQUIRY_COMPLETE";
|
||||||
case BT_HCI_EVT_AUTH_COMPLETE: return "AUTH_COMPLETE";
|
case BT_HCI_EVT_CONN_COMPLETE:
|
||||||
case BT_HCI_EVT_REMOTE_NAME_REQ_COMPLETE: return "REMOTE_NAME_REQ_COMPLETE";
|
return "CONN_COMPLETE";
|
||||||
case BT_HCI_EVT_ENCRYPT_CHANGE: return "ENCRYPT_CHANGE";
|
case BT_HCI_EVT_CONN_REQUEST:
|
||||||
case BT_HCI_EVT_REMOTE_FEATURES: return "REMOTE_FEATURES";
|
return "CONN_REQUEST";
|
||||||
case BT_HCI_EVT_REMOTE_VERSION_INFO: return "REMOTE_VERSION_INFO";
|
case BT_HCI_EVT_DISCONN_COMPLETE:
|
||||||
case BT_HCI_EVT_CMD_COMPLETE: return "CMD_COMPLETE";
|
return "DISCONN_COMPLETE";
|
||||||
case BT_HCI_EVT_CMD_STATUS: return "CMD_STATUS";
|
case BT_HCI_EVT_AUTH_COMPLETE:
|
||||||
case BT_HCI_EVT_ROLE_CHANGE: return "ROLE_CHANGE";
|
return "AUTH_COMPLETE";
|
||||||
case BT_HCI_EVT_NUM_COMPLETED_PACKETS: return "NUM_COMPLETED_PACKETS";
|
case BT_HCI_EVT_REMOTE_NAME_REQ_COMPLETE:
|
||||||
case BT_HCI_EVT_PIN_CODE_REQ: return "PIN_CODE_REQ";
|
return "REMOTE_NAME_REQ_COMPLETE";
|
||||||
case BT_HCI_EVT_LINK_KEY_REQ: return "LINK_KEY_REQ";
|
case BT_HCI_EVT_ENCRYPT_CHANGE:
|
||||||
case BT_HCI_EVT_LINK_KEY_NOTIFY: return "LINK_KEY_NOTIFY";
|
return "ENCRYPT_CHANGE";
|
||||||
case BT_HCI_EVT_DATA_BUF_OVERFLOW: return "DATA_BUF_OVERFLOW";
|
case BT_HCI_EVT_REMOTE_FEATURES:
|
||||||
case BT_HCI_EVT_INQUIRY_RESULT_WITH_RSSI: return "INQUIRY_RESULT_WITH_RSSI";
|
return "REMOTE_FEATURES";
|
||||||
case BT_HCI_EVT_REMOTE_EXT_FEATURES: return "REMOTE_EXT_FEATURES";
|
case BT_HCI_EVT_REMOTE_VERSION_INFO:
|
||||||
case BT_HCI_EVT_SYNC_CONN_COMPLETE: return "SYNC_CONN_COMPLETE";
|
return "REMOTE_VERSION_INFO";
|
||||||
case BT_HCI_EVT_EXTENDED_INQUIRY_RESULT: return "EXTENDED_INQUIRY_RESULT";
|
case BT_HCI_EVT_CMD_COMPLETE:
|
||||||
case BT_HCI_EVT_ENCRYPT_KEY_REFRESH_COMPLETE: return "ENCRYPT_KEY_REFRESH_COMPLETE";
|
return "CMD_COMPLETE";
|
||||||
case BT_HCI_EVT_IO_CAPA_REQ: return "IO_CAPA_REQ";
|
case BT_HCI_EVT_CMD_STATUS:
|
||||||
case BT_HCI_EVT_IO_CAPA_RESP: return "IO_CAPA_RESP";
|
return "CMD_STATUS";
|
||||||
case BT_HCI_EVT_USER_CONFIRM_REQ: return "USER_CONFIRM_REQ";
|
case BT_HCI_EVT_ROLE_CHANGE:
|
||||||
case BT_HCI_EVT_USER_PASSKEY_REQ: return "USER_PASSKEY_REQ";
|
return "ROLE_CHANGE";
|
||||||
case BT_HCI_EVT_SSP_COMPLETE: return "SSP_COMPLETE";
|
case BT_HCI_EVT_NUM_COMPLETED_PACKETS:
|
||||||
case BT_HCI_EVT_USER_PASSKEY_NOTIFY: return "USER_PASSKEY_NOTIFY";
|
return "NUM_COMPLETED_PACKETS";
|
||||||
case BT_HCI_EVT_LE_META_EVENT: return "LE_META_EVENT";
|
case BT_HCI_EVT_PIN_CODE_REQ:
|
||||||
case BT_HCI_EVT_AUTH_PAYLOAD_TIMEOUT_EXP: return "AUTH_PAYLOAD_TIMEOUT_EXP";
|
return "PIN_CODE_REQ";
|
||||||
default: return "";
|
case BT_HCI_EVT_LINK_KEY_REQ:
|
||||||
|
return "LINK_KEY_REQ";
|
||||||
|
case BT_HCI_EVT_LINK_KEY_NOTIFY:
|
||||||
|
return "LINK_KEY_NOTIFY";
|
||||||
|
case BT_HCI_EVT_DATA_BUF_OVERFLOW:
|
||||||
|
return "DATA_BUF_OVERFLOW";
|
||||||
|
case BT_HCI_EVT_INQUIRY_RESULT_WITH_RSSI:
|
||||||
|
return "INQUIRY_RESULT_WITH_RSSI";
|
||||||
|
case BT_HCI_EVT_REMOTE_EXT_FEATURES:
|
||||||
|
return "REMOTE_EXT_FEATURES";
|
||||||
|
case BT_HCI_EVT_SYNC_CONN_COMPLETE:
|
||||||
|
return "SYNC_CONN_COMPLETE";
|
||||||
|
case BT_HCI_EVT_EXTENDED_INQUIRY_RESULT:
|
||||||
|
return "EXTENDED_INQUIRY_RESULT";
|
||||||
|
case BT_HCI_EVT_ENCRYPT_KEY_REFRESH_COMPLETE:
|
||||||
|
return "ENCRYPT_KEY_REFRESH_COMPLETE";
|
||||||
|
case BT_HCI_EVT_IO_CAPA_REQ:
|
||||||
|
return "IO_CAPA_REQ";
|
||||||
|
case BT_HCI_EVT_IO_CAPA_RESP:
|
||||||
|
return "IO_CAPA_RESP";
|
||||||
|
case BT_HCI_EVT_USER_CONFIRM_REQ:
|
||||||
|
return "USER_CONFIRM_REQ";
|
||||||
|
case BT_HCI_EVT_USER_PASSKEY_REQ:
|
||||||
|
return "USER_PASSKEY_REQ";
|
||||||
|
case BT_HCI_EVT_SSP_COMPLETE:
|
||||||
|
return "SSP_COMPLETE";
|
||||||
|
case BT_HCI_EVT_USER_PASSKEY_NOTIFY:
|
||||||
|
return "USER_PASSKEY_NOTIFY";
|
||||||
|
case BT_HCI_EVT_LE_META_EVENT:
|
||||||
|
return "LE_META_EVENT";
|
||||||
|
case BT_HCI_EVT_AUTH_PAYLOAD_TIMEOUT_EXP:
|
||||||
|
return "AUTH_PAYLOAD_TIMEOUT_EXP";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC const char* hci_evt_le_name(uint8_t evt_le) {
|
STATIC const char *hci_evt_le_name(uint8_t evt_le) {
|
||||||
switch (evt_le) {
|
switch (evt_le) {
|
||||||
case BT_HCI_EVT_LE_CONN_COMPLETE: return "LE_CONN_COMPLETE";
|
case BT_HCI_EVT_LE_CONN_COMPLETE:
|
||||||
case BT_HCI_EVT_LE_ADVERTISING_REPORT: return "LE_ADVERTISING_REPORT";
|
return "LE_CONN_COMPLETE";
|
||||||
case BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE: return "LE_CONN_UPDATE_COMPLETE";
|
case BT_HCI_EVT_LE_ADVERTISING_REPORT:
|
||||||
case BT_HCI_EVT_LE_LTK_REQUEST: return "LE_LTK_REQUEST";
|
return "LE_ADVERTISING_REPORT";
|
||||||
case BT_HCI_EVT_LE_CONN_PARAM_REQ: return "LE_CONN_PARAM_REQ";
|
case BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE:
|
||||||
case BT_HCI_EVT_LE_DATA_LEN_CHANGE: return "LE_DATA_LEN_CHANGE";
|
return "LE_CONN_UPDATE_COMPLETE";
|
||||||
case BT_HCI_EVT_LE_P256_PUBLIC_KEY_COMPLETE: return "LE_P256_PUBLIC_KEY_COMPLETE";
|
case BT_HCI_EVT_LE_LTK_REQUEST:
|
||||||
case BT_HCI_EVT_LE_GENERATE_DHKEY_COMPLETE: return "LE_GENERATE_DHKEY_COMPLETE";
|
return "LE_LTK_REQUEST";
|
||||||
case BT_HCI_EVT_LE_ENH_CONN_COMPLETE: return "LE_ENH_CONN_COMPLETE";
|
case BT_HCI_EVT_LE_CONN_PARAM_REQ:
|
||||||
case BT_HCI_EVT_LE_DIRECT_ADV_REPORT: return "LE_DIRECT_ADV_REPORT";
|
return "LE_CONN_PARAM_REQ";
|
||||||
case BT_HCI_EVT_LE_PHY_UPDATE_COMPLETE: return "LE_PHY_UPDATE_COMPLETE";
|
case BT_HCI_EVT_LE_DATA_LEN_CHANGE:
|
||||||
case BT_HCI_EVT_LE_EXT_ADVERTISING_REPORT: return "LE_EXT_ADVERTISING_REPORT";
|
return "LE_DATA_LEN_CHANGE";
|
||||||
case BT_HCI_EVT_LE_PER_ADV_SYNC_ESTABLISHED: return "LE_PER_ADV_SYNC_ESTABLISHED";
|
case BT_HCI_EVT_LE_P256_PUBLIC_KEY_COMPLETE:
|
||||||
case BT_HCI_EVT_LE_PER_ADVERTISING_REPORT: return "LE_PER_ADVERTISING_REPORT";
|
return "LE_P256_PUBLIC_KEY_COMPLETE";
|
||||||
case BT_HCI_EVT_LE_PER_ADV_SYNC_LOST: return "LE_PER_ADV_SYNC_LOST";
|
case BT_HCI_EVT_LE_GENERATE_DHKEY_COMPLETE:
|
||||||
case BT_HCI_EVT_LE_SCAN_TIMEOUT: return "LE_SCAN_TIMEOUT";
|
return "LE_GENERATE_DHKEY_COMPLETE";
|
||||||
case BT_HCI_EVT_LE_ADV_SET_TERMINATED: return "LE_ADV_SET_TERMINATED";
|
case BT_HCI_EVT_LE_ENH_CONN_COMPLETE:
|
||||||
case BT_HCI_EVT_LE_SCAN_REQ_RECEIVED: return "LE_SCAN_REQ_RECEIVED";
|
return "LE_ENH_CONN_COMPLETE";
|
||||||
case BT_HCI_EVT_LE_CHAN_SEL_ALGO: return "LE_CHAN_SEL_ALGO";
|
case BT_HCI_EVT_LE_DIRECT_ADV_REPORT:
|
||||||
default: return "";
|
return "LE_DIRECT_ADV_REPORT";
|
||||||
|
case BT_HCI_EVT_LE_PHY_UPDATE_COMPLETE:
|
||||||
|
return "LE_PHY_UPDATE_COMPLETE";
|
||||||
|
case BT_HCI_EVT_LE_EXT_ADVERTISING_REPORT:
|
||||||
|
return "LE_EXT_ADVERTISING_REPORT";
|
||||||
|
case BT_HCI_EVT_LE_PER_ADV_SYNC_ESTABLISHED:
|
||||||
|
return "LE_PER_ADV_SYNC_ESTABLISHED";
|
||||||
|
case BT_HCI_EVT_LE_PER_ADVERTISING_REPORT:
|
||||||
|
return "LE_PER_ADVERTISING_REPORT";
|
||||||
|
case BT_HCI_EVT_LE_PER_ADV_SYNC_LOST:
|
||||||
|
return "LE_PER_ADV_SYNC_LOST";
|
||||||
|
case BT_HCI_EVT_LE_SCAN_TIMEOUT:
|
||||||
|
return "LE_SCAN_TIMEOUT";
|
||||||
|
case BT_HCI_EVT_LE_ADV_SET_TERMINATED:
|
||||||
|
return "LE_ADV_SET_TERMINATED";
|
||||||
|
case BT_HCI_EVT_LE_SCAN_REQ_RECEIVED:
|
||||||
|
return "LE_SCAN_REQ_RECEIVED";
|
||||||
|
case BT_HCI_EVT_LE_CHAN_SEL_ALGO:
|
||||||
|
return "LE_CHAN_SEL_ALGO";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC const char* hci_opcode_name(uint16_t opcode) {
|
STATIC const char *hci_opcode_name(uint16_t opcode) {
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case BT_OP_NOP: return "NOP";
|
case BT_OP_NOP:
|
||||||
case BT_HCI_OP_INQUIRY: return "INQUIRY";
|
return "NOP";
|
||||||
case BT_HCI_OP_INQUIRY_CANCEL: return "INQUIRY_CANCEL";
|
case BT_HCI_OP_INQUIRY:
|
||||||
case BT_HCI_OP_CONNECT: return "CONNECT";
|
return "INQUIRY";
|
||||||
case BT_HCI_OP_DISCONNECT: return "DISCONNECT";
|
case BT_HCI_OP_INQUIRY_CANCEL:
|
||||||
case BT_HCI_OP_CONNECT_CANCEL: return "CONNECT_CANCEL";
|
return "INQUIRY_CANCEL";
|
||||||
case BT_HCI_OP_ACCEPT_CONN_REQ: return "ACCEPT_CONN_REQ";
|
case BT_HCI_OP_CONNECT:
|
||||||
case BT_HCI_OP_SETUP_SYNC_CONN: return "SETUP_SYNC_CONN";
|
return "CONNECT";
|
||||||
case BT_HCI_OP_ACCEPT_SYNC_CONN_REQ: return "ACCEPT_SYNC_CONN_REQ";
|
case BT_HCI_OP_DISCONNECT:
|
||||||
case BT_HCI_OP_REJECT_CONN_REQ: return "REJECT_CONN_REQ";
|
return "DISCONNECT";
|
||||||
case BT_HCI_OP_LINK_KEY_REPLY: return "LINK_KEY_REPLY";
|
case BT_HCI_OP_CONNECT_CANCEL:
|
||||||
case BT_HCI_OP_LINK_KEY_NEG_REPLY: return "LINK_KEY_NEG_REPLY";
|
return "CONNECT_CANCEL";
|
||||||
case BT_HCI_OP_PIN_CODE_REPLY: return "PIN_CODE_REPLY";
|
case BT_HCI_OP_ACCEPT_CONN_REQ:
|
||||||
case BT_HCI_OP_PIN_CODE_NEG_REPLY: return "PIN_CODE_NEG_REPLY";
|
return "ACCEPT_CONN_REQ";
|
||||||
case BT_HCI_OP_AUTH_REQUESTED: return "AUTH_REQUESTED";
|
case BT_HCI_OP_SETUP_SYNC_CONN:
|
||||||
case BT_HCI_OP_SET_CONN_ENCRYPT: return "SET_CONN_ENCRYPT";
|
return "SETUP_SYNC_CONN";
|
||||||
case BT_HCI_OP_REMOTE_NAME_REQUEST: return "REMOTE_NAME_REQUEST";
|
case BT_HCI_OP_ACCEPT_SYNC_CONN_REQ:
|
||||||
case BT_HCI_OP_REMOTE_NAME_CANCEL: return "REMOTE_NAME_CANCEL";
|
return "ACCEPT_SYNC_CONN_REQ";
|
||||||
case BT_HCI_OP_READ_REMOTE_FEATURES: return "READ_REMOTE_FEATURES";
|
case BT_HCI_OP_REJECT_CONN_REQ:
|
||||||
case BT_HCI_OP_READ_REMOTE_EXT_FEATURES: return "READ_REMOTE_EXT_FEATURES";
|
return "REJECT_CONN_REQ";
|
||||||
case BT_HCI_OP_READ_REMOTE_VERSION_INFO: return "READ_REMOTE_VERSION_INFO";
|
case BT_HCI_OP_LINK_KEY_REPLY:
|
||||||
case BT_HCI_OP_IO_CAPABILITY_REPLY: return "IO_CAPABILITY_REPLY";
|
return "LINK_KEY_REPLY";
|
||||||
case BT_HCI_OP_USER_CONFIRM_REPLY: return "USER_CONFIRM_REPLY";
|
case BT_HCI_OP_LINK_KEY_NEG_REPLY:
|
||||||
case BT_HCI_OP_USER_CONFIRM_NEG_REPLY: return "USER_CONFIRM_NEG_REPLY";
|
return "LINK_KEY_NEG_REPLY";
|
||||||
case BT_HCI_OP_USER_PASSKEY_REPLY: return "USER_PASSKEY_REPLY";
|
case BT_HCI_OP_PIN_CODE_REPLY:
|
||||||
case BT_HCI_OP_USER_PASSKEY_NEG_REPLY: return "USER_PASSKEY_NEG_REPLY";
|
return "PIN_CODE_REPLY";
|
||||||
case BT_HCI_OP_IO_CAPABILITY_NEG_REPLY: return "IO_CAPABILITY_NEG_REPLY";
|
case BT_HCI_OP_PIN_CODE_NEG_REPLY:
|
||||||
case BT_HCI_OP_SET_EVENT_MASK: return "SET_EVENT_MASK";
|
return "PIN_CODE_NEG_REPLY";
|
||||||
case BT_HCI_OP_RESET: return "RESET";
|
case BT_HCI_OP_AUTH_REQUESTED:
|
||||||
case BT_HCI_OP_WRITE_LOCAL_NAME: return "WRITE_LOCAL_NAME";
|
return "AUTH_REQUESTED";
|
||||||
case BT_HCI_OP_WRITE_PAGE_TIMEOUT: return "WRITE_PAGE_TIMEOUT";
|
case BT_HCI_OP_SET_CONN_ENCRYPT:
|
||||||
case BT_HCI_OP_WRITE_SCAN_ENABLE: return "WRITE_SCAN_ENABLE";
|
return "SET_CONN_ENCRYPT";
|
||||||
case BT_HCI_OP_READ_TX_POWER_LEVEL: return "READ_TX_POWER_LEVEL";
|
case BT_HCI_OP_REMOTE_NAME_REQUEST:
|
||||||
case BT_HCI_OP_SET_CTL_TO_HOST_FLOW: return "SET_CTL_TO_HOST_FLOW";
|
return "REMOTE_NAME_REQUEST";
|
||||||
case BT_HCI_OP_HOST_BUFFER_SIZE: return "HOST_BUFFER_SIZE";
|
case BT_HCI_OP_REMOTE_NAME_CANCEL:
|
||||||
case BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS: return "HOST_NUM_COMPLETED_PACKETS";
|
return "REMOTE_NAME_CANCEL";
|
||||||
case BT_HCI_OP_WRITE_INQUIRY_MODE: return "WRITE_INQUIRY_MODE";
|
case BT_HCI_OP_READ_REMOTE_FEATURES:
|
||||||
case BT_HCI_OP_WRITE_SSP_MODE: return "WRITE_SSP_MODE";
|
return "READ_REMOTE_FEATURES";
|
||||||
case BT_HCI_OP_SET_EVENT_MASK_PAGE_2: return "SET_EVENT_MASK_PAGE_2";
|
case BT_HCI_OP_READ_REMOTE_EXT_FEATURES:
|
||||||
case BT_HCI_OP_LE_WRITE_LE_HOST_SUPP: return "LE_WRITE_LE_HOST_SUPP";
|
return "READ_REMOTE_EXT_FEATURES";
|
||||||
case BT_HCI_OP_WRITE_SC_HOST_SUPP: return "WRITE_SC_HOST_SUPP";
|
case BT_HCI_OP_READ_REMOTE_VERSION_INFO:
|
||||||
case BT_HCI_OP_READ_AUTH_PAYLOAD_TIMEOUT: return "READ_AUTH_PAYLOAD_TIMEOUT";
|
return "READ_REMOTE_VERSION_INFO";
|
||||||
case BT_HCI_OP_WRITE_AUTH_PAYLOAD_TIMEOUT: return "WRITE_AUTH_PAYLOAD_TIMEOUT";
|
case BT_HCI_OP_IO_CAPABILITY_REPLY:
|
||||||
case BT_HCI_OP_READ_LOCAL_VERSION_INFO: return "READ_LOCAL_VERSION_INFO";
|
return "IO_CAPABILITY_REPLY";
|
||||||
case BT_HCI_OP_READ_SUPPORTED_COMMANDS: return "READ_SUPPORTED_COMMANDS";
|
case BT_HCI_OP_USER_CONFIRM_REPLY:
|
||||||
case BT_HCI_OP_READ_LOCAL_EXT_FEATURES: return "READ_LOCAL_EXT_FEATURES";
|
return "USER_CONFIRM_REPLY";
|
||||||
case BT_HCI_OP_READ_LOCAL_FEATURES: return "READ_LOCAL_FEATURES";
|
case BT_HCI_OP_USER_CONFIRM_NEG_REPLY:
|
||||||
case BT_HCI_OP_READ_BUFFER_SIZE: return "READ_BUFFER_SIZE";
|
return "USER_CONFIRM_NEG_REPLY";
|
||||||
case BT_HCI_OP_READ_BD_ADDR: return "READ_BD_ADDR";
|
case BT_HCI_OP_USER_PASSKEY_REPLY:
|
||||||
case BT_HCI_OP_READ_RSSI: return "READ_RSSI";
|
return "USER_PASSKEY_REPLY";
|
||||||
case BT_HCI_OP_READ_ENCRYPTION_KEY_SIZE: return "READ_ENCRYPTION_KEY_SIZE";
|
case BT_HCI_OP_USER_PASSKEY_NEG_REPLY:
|
||||||
case BT_HCI_OP_LE_SET_EVENT_MASK: return "LE_SET_EVENT_MASK";
|
return "USER_PASSKEY_NEG_REPLY";
|
||||||
case BT_HCI_OP_LE_READ_BUFFER_SIZE: return "LE_READ_BUFFER_SIZE";
|
case BT_HCI_OP_IO_CAPABILITY_NEG_REPLY:
|
||||||
case BT_HCI_OP_LE_READ_LOCAL_FEATURES: return "LE_READ_LOCAL_FEATURES";
|
return "IO_CAPABILITY_NEG_REPLY";
|
||||||
case BT_HCI_OP_LE_SET_RANDOM_ADDRESS: return "LE_SET_RANDOM_ADDRESS";
|
case BT_HCI_OP_SET_EVENT_MASK:
|
||||||
case BT_HCI_OP_LE_SET_ADV_PARAM: return "LE_SET_ADV_PARAM";
|
return "SET_EVENT_MASK";
|
||||||
case BT_HCI_OP_LE_READ_ADV_CHAN_TX_POWER: return "LE_READ_ADV_CHAN_TX_POWER";
|
case BT_HCI_OP_RESET:
|
||||||
case BT_HCI_OP_LE_SET_ADV_DATA: return "LE_SET_ADV_DATA";
|
return "RESET";
|
||||||
case BT_HCI_OP_LE_SET_SCAN_RSP_DATA: return "LE_SET_SCAN_RSP_DATA";
|
case BT_HCI_OP_WRITE_LOCAL_NAME:
|
||||||
case BT_HCI_OP_LE_SET_ADV_ENABLE: return "LE_SET_ADV_ENABLE";
|
return "WRITE_LOCAL_NAME";
|
||||||
case BT_HCI_OP_LE_SET_SCAN_PARAM: return "LE_SET_SCAN_PARAM";
|
case BT_HCI_OP_WRITE_PAGE_TIMEOUT:
|
||||||
case BT_HCI_OP_LE_SET_SCAN_ENABLE: return "LE_SET_SCAN_ENABLE";
|
return "WRITE_PAGE_TIMEOUT";
|
||||||
case BT_HCI_OP_LE_CREATE_CONN: return "LE_CREATE_CONN";
|
case BT_HCI_OP_WRITE_SCAN_ENABLE:
|
||||||
case BT_HCI_OP_LE_CREATE_CONN_CANCEL: return "LE_CREATE_CONN_CANCEL";
|
return "WRITE_SCAN_ENABLE";
|
||||||
case BT_HCI_OP_LE_READ_WL_SIZE: return "LE_READ_WL_SIZE";
|
case BT_HCI_OP_READ_TX_POWER_LEVEL:
|
||||||
case BT_HCI_OP_LE_CLEAR_WL: return "LE_CLEAR_WL";
|
return "READ_TX_POWER_LEVEL";
|
||||||
case BT_HCI_OP_LE_ADD_DEV_TO_WL: return "LE_ADD_DEV_TO_WL";
|
case BT_HCI_OP_SET_CTL_TO_HOST_FLOW:
|
||||||
case BT_HCI_OP_LE_REM_DEV_FROM_WL: return "LE_REM_DEV_FROM_WL";
|
return "SET_CTL_TO_HOST_FLOW";
|
||||||
case BT_HCI_OP_LE_CONN_UPDATE: return "LE_CONN_UPDATE";
|
case BT_HCI_OP_HOST_BUFFER_SIZE:
|
||||||
case BT_HCI_OP_LE_SET_HOST_CHAN_CLASSIF: return "LE_SET_HOST_CHAN_CLASSIF";
|
return "HOST_BUFFER_SIZE";
|
||||||
case BT_HCI_OP_LE_READ_CHAN_MAP: return "LE_READ_CHAN_MAP";
|
case BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS:
|
||||||
case BT_HCI_OP_LE_READ_REMOTE_FEATURES: return "LE_READ_REMOTE_FEATURES";
|
return "HOST_NUM_COMPLETED_PACKETS";
|
||||||
case BT_HCI_OP_LE_ENCRYPT: return "LE_ENCRYPT";
|
case BT_HCI_OP_WRITE_INQUIRY_MODE:
|
||||||
case BT_HCI_OP_LE_RAND: return "LE_RAND";
|
return "WRITE_INQUIRY_MODE";
|
||||||
case BT_HCI_OP_LE_START_ENCRYPTION: return "LE_START_ENCRYPTION";
|
case BT_HCI_OP_WRITE_SSP_MODE:
|
||||||
case BT_HCI_OP_LE_LTK_REQ_REPLY: return "LE_LTK_REQ_REPLY";
|
return "WRITE_SSP_MODE";
|
||||||
case BT_HCI_OP_LE_LTK_REQ_NEG_REPLY: return "LE_LTK_REQ_NEG_REPLY";
|
case BT_HCI_OP_SET_EVENT_MASK_PAGE_2:
|
||||||
case BT_HCI_OP_LE_READ_SUPP_STATES: return "LE_READ_SUPP_STATES";
|
return "SET_EVENT_MASK_PAGE_2";
|
||||||
case BT_HCI_OP_LE_RX_TEST: return "LE_RX_TEST";
|
case BT_HCI_OP_LE_WRITE_LE_HOST_SUPP:
|
||||||
case BT_HCI_OP_LE_TX_TEST: return "LE_TX_TEST";
|
return "LE_WRITE_LE_HOST_SUPP";
|
||||||
case BT_HCI_OP_LE_TEST_END: return "LE_TEST_END";
|
case BT_HCI_OP_WRITE_SC_HOST_SUPP:
|
||||||
case BT_HCI_OP_LE_CONN_PARAM_REQ_REPLY: return "LE_CONN_PARAM_REQ_REPLY";
|
return "WRITE_SC_HOST_SUPP";
|
||||||
case BT_HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY: return "LE_CONN_PARAM_REQ_NEG_REPLY";
|
case BT_HCI_OP_READ_AUTH_PAYLOAD_TIMEOUT:
|
||||||
case BT_HCI_OP_LE_SET_DATA_LEN: return "LE_SET_DATA_LEN";
|
return "READ_AUTH_PAYLOAD_TIMEOUT";
|
||||||
case BT_HCI_OP_LE_READ_DEFAULT_DATA_LEN: return "LE_READ_DEFAULT_DATA_LEN";
|
case BT_HCI_OP_WRITE_AUTH_PAYLOAD_TIMEOUT:
|
||||||
case BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN: return "LE_WRITE_DEFAULT_DATA_LEN";
|
return "WRITE_AUTH_PAYLOAD_TIMEOUT";
|
||||||
case BT_HCI_OP_LE_P256_PUBLIC_KEY: return "LE_P256_PUBLIC_KEY";
|
case BT_HCI_OP_READ_LOCAL_VERSION_INFO:
|
||||||
case BT_HCI_OP_LE_GENERATE_DHKEY: return "LE_GENERATE_DHKEY";
|
return "READ_LOCAL_VERSION_INFO";
|
||||||
case BT_HCI_OP_LE_ADD_DEV_TO_RL: return "LE_ADD_DEV_TO_RL";
|
case BT_HCI_OP_READ_SUPPORTED_COMMANDS:
|
||||||
case BT_HCI_OP_LE_REM_DEV_FROM_RL: return "LE_REM_DEV_FROM_RL";
|
return "READ_SUPPORTED_COMMANDS";
|
||||||
case BT_HCI_OP_LE_CLEAR_RL: return "LE_CLEAR_RL";
|
case BT_HCI_OP_READ_LOCAL_EXT_FEATURES:
|
||||||
case BT_HCI_OP_LE_READ_RL_SIZE: return "LE_READ_RL_SIZE";
|
return "READ_LOCAL_EXT_FEATURES";
|
||||||
case BT_HCI_OP_LE_READ_PEER_RPA: return "LE_READ_PEER_RPA";
|
case BT_HCI_OP_READ_LOCAL_FEATURES:
|
||||||
case BT_HCI_OP_LE_READ_LOCAL_RPA: return "LE_READ_LOCAL_RPA";
|
return "READ_LOCAL_FEATURES";
|
||||||
case BT_HCI_OP_LE_SET_ADDR_RES_ENABLE: return "LE_SET_ADDR_RES_ENABLE";
|
case BT_HCI_OP_READ_BUFFER_SIZE:
|
||||||
case BT_HCI_OP_LE_SET_RPA_TIMEOUT: return "LE_SET_RPA_TIMEOUT";
|
return "READ_BUFFER_SIZE";
|
||||||
case BT_HCI_OP_LE_READ_MAX_DATA_LEN: return "LE_READ_MAX_DATA_LEN";
|
case BT_HCI_OP_READ_BD_ADDR:
|
||||||
case BT_HCI_OP_LE_READ_PHY: return "LE_READ_PHY";
|
return "READ_BD_ADDR";
|
||||||
case BT_HCI_OP_LE_SET_DEFAULT_PHY: return "LE_SET_DEFAULT_PHY";
|
case BT_HCI_OP_READ_RSSI:
|
||||||
case BT_HCI_OP_LE_SET_PHY: return "LE_SET_PHY";
|
return "READ_RSSI";
|
||||||
case BT_HCI_OP_LE_ENH_RX_TEST: return "LE_ENH_RX_TEST";
|
case BT_HCI_OP_READ_ENCRYPTION_KEY_SIZE:
|
||||||
case BT_HCI_OP_LE_ENH_TX_TEST: return "LE_ENH_TX_TEST";
|
return "READ_ENCRYPTION_KEY_SIZE";
|
||||||
case BT_HCI_OP_LE_SET_ADV_SET_RANDOM_ADDR: return "LE_SET_ADV_SET_RANDOM_ADDR";
|
case BT_HCI_OP_LE_SET_EVENT_MASK:
|
||||||
case BT_HCI_OP_LE_SET_EXT_ADV_PARAM: return "LE_SET_EXT_ADV_PARAM";
|
return "LE_SET_EVENT_MASK";
|
||||||
case BT_HCI_OP_LE_SET_EXT_ADV_DATA: return "LE_SET_EXT_ADV_DATA";
|
case BT_HCI_OP_LE_READ_BUFFER_SIZE:
|
||||||
case BT_HCI_OP_LE_SET_EXT_SCAN_RSP_DATA: return "LE_SET_EXT_SCAN_RSP_DATA";
|
return "LE_READ_BUFFER_SIZE";
|
||||||
case BT_HCI_OP_LE_SET_EXT_ADV_ENABLE: return "LE_SET_EXT_ADV_ENABLE";
|
case BT_HCI_OP_LE_READ_LOCAL_FEATURES:
|
||||||
case BT_HCI_OP_LE_READ_MAX_ADV_DATA_LEN: return "LE_READ_MAX_ADV_DATA_LEN";
|
return "LE_READ_LOCAL_FEATURES";
|
||||||
case BT_HCI_OP_LE_READ_NUM_ADV_SETS: return "LE_READ_NUM_ADV_SETS";
|
case BT_HCI_OP_LE_SET_RANDOM_ADDRESS:
|
||||||
case BT_HCI_OP_LE_REMOVE_ADV_SET: return "LE_REMOVE_ADV_SET";
|
return "LE_SET_RANDOM_ADDRESS";
|
||||||
case BT_HCI_OP_CLEAR_ADV_SETS: return "CLEAR_ADV_SETS";
|
case BT_HCI_OP_LE_SET_ADV_PARAM:
|
||||||
case BT_HCI_OP_LE_SET_PER_ADV_PARAM: return "LE_SET_PER_ADV_PARAM";
|
return "LE_SET_ADV_PARAM";
|
||||||
case BT_HCI_OP_LE_SET_PER_ADV_DATA: return "LE_SET_PER_ADV_DATA";
|
case BT_HCI_OP_LE_READ_ADV_CHAN_TX_POWER:
|
||||||
case BT_HCI_OP_LE_SET_PER_ADV_ENABLE: return "LE_SET_PER_ADV_ENABLE";
|
return "LE_READ_ADV_CHAN_TX_POWER";
|
||||||
case BT_HCI_OP_LE_SET_EXT_SCAN_PARAM: return "LE_SET_EXT_SCAN_PARAM";
|
case BT_HCI_OP_LE_SET_ADV_DATA:
|
||||||
case BT_HCI_OP_LE_SET_EXT_SCAN_ENABLE: return "LE_SET_EXT_SCAN_ENABLE";
|
return "LE_SET_ADV_DATA";
|
||||||
case BT_HCI_OP_LE_EXT_CREATE_CONN: return "LE_EXT_CREATE_CONN";
|
case BT_HCI_OP_LE_SET_SCAN_RSP_DATA:
|
||||||
case BT_HCI_OP_LE_PER_ADV_CREATE_SYNC: return "LE_PER_ADV_CREATE_SYNC";
|
return "LE_SET_SCAN_RSP_DATA";
|
||||||
case BT_HCI_OP_LE_PER_ADV_CREATE_SYNC_CANCEL: return "LE_PER_ADV_CREATE_SYNC_CANCEL";
|
case BT_HCI_OP_LE_SET_ADV_ENABLE:
|
||||||
case BT_HCI_OP_LE_PER_ADV_TERMINATE_SYNC: return "LE_PER_ADV_TERMINATE_SYNC";
|
return "LE_SET_ADV_ENABLE";
|
||||||
case BT_HCI_OP_LE_ADD_DEV_TO_PER_ADV_LIST: return "LE_ADD_DEV_TO_PER_ADV_LIST";
|
case BT_HCI_OP_LE_SET_SCAN_PARAM:
|
||||||
case BT_HCI_OP_LE_REM_DEV_FROM_PER_ADV_LIST: return "LE_REM_DEV_FROM_PER_ADV_LIST";
|
return "LE_SET_SCAN_PARAM";
|
||||||
case BT_HCI_OP_LE_CLEAR_PER_ADV_LIST: return "LE_CLEAR_PER_ADV_LIST";
|
case BT_HCI_OP_LE_SET_SCAN_ENABLE:
|
||||||
case BT_HCI_OP_LE_READ_PER_ADV_LIST_SIZE: return "LE_READ_PER_ADV_LIST_SIZE";
|
return "LE_SET_SCAN_ENABLE";
|
||||||
case BT_HCI_OP_LE_READ_TX_POWER: return "LE_READ_TX_POWER";
|
case BT_HCI_OP_LE_CREATE_CONN:
|
||||||
case BT_HCI_OP_LE_READ_RF_PATH_COMP: return "LE_READ_RF_PATH_COMP";
|
return "LE_CREATE_CONN";
|
||||||
case BT_HCI_OP_LE_WRITE_RF_PATH_COMP: return "LE_WRITE_RF_PATH_COMP";
|
case BT_HCI_OP_LE_CREATE_CONN_CANCEL:
|
||||||
case BT_HCI_OP_LE_SET_PRIVACY_MODE: return "LE_SET_PRIVACY_MODE";
|
return "LE_CREATE_CONN_CANCEL";
|
||||||
default: return "";
|
case BT_HCI_OP_LE_READ_WL_SIZE:
|
||||||
|
return "LE_READ_WL_SIZE";
|
||||||
|
case BT_HCI_OP_LE_CLEAR_WL:
|
||||||
|
return "LE_CLEAR_WL";
|
||||||
|
case BT_HCI_OP_LE_ADD_DEV_TO_WL:
|
||||||
|
return "LE_ADD_DEV_TO_WL";
|
||||||
|
case BT_HCI_OP_LE_REM_DEV_FROM_WL:
|
||||||
|
return "LE_REM_DEV_FROM_WL";
|
||||||
|
case BT_HCI_OP_LE_CONN_UPDATE:
|
||||||
|
return "LE_CONN_UPDATE";
|
||||||
|
case BT_HCI_OP_LE_SET_HOST_CHAN_CLASSIF:
|
||||||
|
return "LE_SET_HOST_CHAN_CLASSIF";
|
||||||
|
case BT_HCI_OP_LE_READ_CHAN_MAP:
|
||||||
|
return "LE_READ_CHAN_MAP";
|
||||||
|
case BT_HCI_OP_LE_READ_REMOTE_FEATURES:
|
||||||
|
return "LE_READ_REMOTE_FEATURES";
|
||||||
|
case BT_HCI_OP_LE_ENCRYPT:
|
||||||
|
return "LE_ENCRYPT";
|
||||||
|
case BT_HCI_OP_LE_RAND:
|
||||||
|
return "LE_RAND";
|
||||||
|
case BT_HCI_OP_LE_START_ENCRYPTION:
|
||||||
|
return "LE_START_ENCRYPTION";
|
||||||
|
case BT_HCI_OP_LE_LTK_REQ_REPLY:
|
||||||
|
return "LE_LTK_REQ_REPLY";
|
||||||
|
case BT_HCI_OP_LE_LTK_REQ_NEG_REPLY:
|
||||||
|
return "LE_LTK_REQ_NEG_REPLY";
|
||||||
|
case BT_HCI_OP_LE_READ_SUPP_STATES:
|
||||||
|
return "LE_READ_SUPP_STATES";
|
||||||
|
case BT_HCI_OP_LE_RX_TEST:
|
||||||
|
return "LE_RX_TEST";
|
||||||
|
case BT_HCI_OP_LE_TX_TEST:
|
||||||
|
return "LE_TX_TEST";
|
||||||
|
case BT_HCI_OP_LE_TEST_END:
|
||||||
|
return "LE_TEST_END";
|
||||||
|
case BT_HCI_OP_LE_CONN_PARAM_REQ_REPLY:
|
||||||
|
return "LE_CONN_PARAM_REQ_REPLY";
|
||||||
|
case BT_HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY:
|
||||||
|
return "LE_CONN_PARAM_REQ_NEG_REPLY";
|
||||||
|
case BT_HCI_OP_LE_SET_DATA_LEN:
|
||||||
|
return "LE_SET_DATA_LEN";
|
||||||
|
case BT_HCI_OP_LE_READ_DEFAULT_DATA_LEN:
|
||||||
|
return "LE_READ_DEFAULT_DATA_LEN";
|
||||||
|
case BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN:
|
||||||
|
return "LE_WRITE_DEFAULT_DATA_LEN";
|
||||||
|
case BT_HCI_OP_LE_P256_PUBLIC_KEY:
|
||||||
|
return "LE_P256_PUBLIC_KEY";
|
||||||
|
case BT_HCI_OP_LE_GENERATE_DHKEY:
|
||||||
|
return "LE_GENERATE_DHKEY";
|
||||||
|
case BT_HCI_OP_LE_ADD_DEV_TO_RL:
|
||||||
|
return "LE_ADD_DEV_TO_RL";
|
||||||
|
case BT_HCI_OP_LE_REM_DEV_FROM_RL:
|
||||||
|
return "LE_REM_DEV_FROM_RL";
|
||||||
|
case BT_HCI_OP_LE_CLEAR_RL:
|
||||||
|
return "LE_CLEAR_RL";
|
||||||
|
case BT_HCI_OP_LE_READ_RL_SIZE:
|
||||||
|
return "LE_READ_RL_SIZE";
|
||||||
|
case BT_HCI_OP_LE_READ_PEER_RPA:
|
||||||
|
return "LE_READ_PEER_RPA";
|
||||||
|
case BT_HCI_OP_LE_READ_LOCAL_RPA:
|
||||||
|
return "LE_READ_LOCAL_RPA";
|
||||||
|
case BT_HCI_OP_LE_SET_ADDR_RES_ENABLE:
|
||||||
|
return "LE_SET_ADDR_RES_ENABLE";
|
||||||
|
case BT_HCI_OP_LE_SET_RPA_TIMEOUT:
|
||||||
|
return "LE_SET_RPA_TIMEOUT";
|
||||||
|
case BT_HCI_OP_LE_READ_MAX_DATA_LEN:
|
||||||
|
return "LE_READ_MAX_DATA_LEN";
|
||||||
|
case BT_HCI_OP_LE_READ_PHY:
|
||||||
|
return "LE_READ_PHY";
|
||||||
|
case BT_HCI_OP_LE_SET_DEFAULT_PHY:
|
||||||
|
return "LE_SET_DEFAULT_PHY";
|
||||||
|
case BT_HCI_OP_LE_SET_PHY:
|
||||||
|
return "LE_SET_PHY";
|
||||||
|
case BT_HCI_OP_LE_ENH_RX_TEST:
|
||||||
|
return "LE_ENH_RX_TEST";
|
||||||
|
case BT_HCI_OP_LE_ENH_TX_TEST:
|
||||||
|
return "LE_ENH_TX_TEST";
|
||||||
|
case BT_HCI_OP_LE_SET_ADV_SET_RANDOM_ADDR:
|
||||||
|
return "LE_SET_ADV_SET_RANDOM_ADDR";
|
||||||
|
case BT_HCI_OP_LE_SET_EXT_ADV_PARAM:
|
||||||
|
return "LE_SET_EXT_ADV_PARAM";
|
||||||
|
case BT_HCI_OP_LE_SET_EXT_ADV_DATA:
|
||||||
|
return "LE_SET_EXT_ADV_DATA";
|
||||||
|
case BT_HCI_OP_LE_SET_EXT_SCAN_RSP_DATA:
|
||||||
|
return "LE_SET_EXT_SCAN_RSP_DATA";
|
||||||
|
case BT_HCI_OP_LE_SET_EXT_ADV_ENABLE:
|
||||||
|
return "LE_SET_EXT_ADV_ENABLE";
|
||||||
|
case BT_HCI_OP_LE_READ_MAX_ADV_DATA_LEN:
|
||||||
|
return "LE_READ_MAX_ADV_DATA_LEN";
|
||||||
|
case BT_HCI_OP_LE_READ_NUM_ADV_SETS:
|
||||||
|
return "LE_READ_NUM_ADV_SETS";
|
||||||
|
case BT_HCI_OP_LE_REMOVE_ADV_SET:
|
||||||
|
return "LE_REMOVE_ADV_SET";
|
||||||
|
case BT_HCI_OP_CLEAR_ADV_SETS:
|
||||||
|
return "CLEAR_ADV_SETS";
|
||||||
|
case BT_HCI_OP_LE_SET_PER_ADV_PARAM:
|
||||||
|
return "LE_SET_PER_ADV_PARAM";
|
||||||
|
case BT_HCI_OP_LE_SET_PER_ADV_DATA:
|
||||||
|
return "LE_SET_PER_ADV_DATA";
|
||||||
|
case BT_HCI_OP_LE_SET_PER_ADV_ENABLE:
|
||||||
|
return "LE_SET_PER_ADV_ENABLE";
|
||||||
|
case BT_HCI_OP_LE_SET_EXT_SCAN_PARAM:
|
||||||
|
return "LE_SET_EXT_SCAN_PARAM";
|
||||||
|
case BT_HCI_OP_LE_SET_EXT_SCAN_ENABLE:
|
||||||
|
return "LE_SET_EXT_SCAN_ENABLE";
|
||||||
|
case BT_HCI_OP_LE_EXT_CREATE_CONN:
|
||||||
|
return "LE_EXT_CREATE_CONN";
|
||||||
|
case BT_HCI_OP_LE_PER_ADV_CREATE_SYNC:
|
||||||
|
return "LE_PER_ADV_CREATE_SYNC";
|
||||||
|
case BT_HCI_OP_LE_PER_ADV_CREATE_SYNC_CANCEL:
|
||||||
|
return "LE_PER_ADV_CREATE_SYNC_CANCEL";
|
||||||
|
case BT_HCI_OP_LE_PER_ADV_TERMINATE_SYNC:
|
||||||
|
return "LE_PER_ADV_TERMINATE_SYNC";
|
||||||
|
case BT_HCI_OP_LE_ADD_DEV_TO_PER_ADV_LIST:
|
||||||
|
return "LE_ADD_DEV_TO_PER_ADV_LIST";
|
||||||
|
case BT_HCI_OP_LE_REM_DEV_FROM_PER_ADV_LIST:
|
||||||
|
return "LE_REM_DEV_FROM_PER_ADV_LIST";
|
||||||
|
case BT_HCI_OP_LE_CLEAR_PER_ADV_LIST:
|
||||||
|
return "LE_CLEAR_PER_ADV_LIST";
|
||||||
|
case BT_HCI_OP_LE_READ_PER_ADV_LIST_SIZE:
|
||||||
|
return "LE_READ_PER_ADV_LIST_SIZE";
|
||||||
|
case BT_HCI_OP_LE_READ_TX_POWER:
|
||||||
|
return "LE_READ_TX_POWER";
|
||||||
|
case BT_HCI_OP_LE_READ_RF_PATH_COMP:
|
||||||
|
return "LE_READ_RF_PATH_COMP";
|
||||||
|
case BT_HCI_OP_LE_WRITE_RF_PATH_COMP:
|
||||||
|
return "LE_WRITE_RF_PATH_COMP";
|
||||||
|
case BT_HCI_OP_LE_SET_PRIVACY_MODE:
|
||||||
|
return "LE_SET_PRIVACY_MODE";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
STATIC void dump_cmd_pkt(bool tx, uint8_t pkt_len, uint8_t pkt_data[]) {
|
STATIC void dump_cmd_pkt(bool tx, uint8_t pkt_len, uint8_t pkt_data[]) {
|
||||||
h4_hci_cmd_pkt_t *pkt = (h4_hci_cmd_pkt_t *) pkt_data;
|
h4_hci_cmd_pkt_t *pkt = (h4_hci_cmd_pkt_t *)pkt_data;
|
||||||
mp_printf(&mp_plat_print,
|
mp_printf(&mp_plat_print,
|
||||||
"%s HCI COMMAND (%x) op: %s (%04x), len: %d, data: ",
|
"%s HCI COMMAND (%x) op: %s (%04x), len: %d, data: ",
|
||||||
tx ? "TX->" : "RX<-",
|
tx ? "TX->" : "RX<-",
|
||||||
pkt->pkt_type,
|
pkt->pkt_type,
|
||||||
hci_opcode_name(pkt->opcode), pkt->opcode, pkt->param_len);
|
hci_opcode_name(pkt->opcode), pkt->opcode, pkt->param_len);
|
||||||
for (size_t i = 0; i < pkt->param_len; i++) {
|
for (size_t i = 0; i < pkt->param_len; i++) {
|
||||||
mp_printf(&mp_plat_print, "%02x ", pkt->params[i]);
|
mp_printf(&mp_plat_print, "%02x ", pkt->params[i]);
|
||||||
}
|
}
|
||||||
@ -278,12 +492,12 @@ STATIC void dump_cmd_pkt(bool tx, uint8_t pkt_len, uint8_t pkt_data[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void dump_acl_pkt(bool tx, uint8_t pkt_len, uint8_t pkt_data[]) {
|
STATIC void dump_acl_pkt(bool tx, uint8_t pkt_len, uint8_t pkt_data[]) {
|
||||||
h4_hci_acl_pkt_t *pkt = (h4_hci_acl_pkt_t *) pkt_data;
|
h4_hci_acl_pkt_t *pkt = (h4_hci_acl_pkt_t *)pkt_data;
|
||||||
acl_data_t *acl = (acl_data_t *) pkt->data;
|
acl_data_t *acl = (acl_data_t *)pkt->data;
|
||||||
|
|
||||||
mp_printf(&mp_plat_print,
|
mp_printf(&mp_plat_print,
|
||||||
"%s HCI ACLDATA (%x) ",
|
"%s HCI ACLDATA (%x) ",
|
||||||
tx ? "TX->" : "RX<-", pkt->pkt_type);
|
tx ? "TX->" : "RX<-", pkt->pkt_type);
|
||||||
|
|
||||||
if (pkt->pb != ACL_DATA_PB_MIDDLE && acl->cid == BT_L2CAP_CID_ATT) {
|
if (pkt->pb != ACL_DATA_PB_MIDDLE && acl->cid == BT_L2CAP_CID_ATT) {
|
||||||
// This is the start of a fragmented acl_data packet or is a full packet,
|
// This is the start of a fragmented acl_data packet or is a full packet,
|
||||||
@ -292,14 +506,14 @@ STATIC void dump_acl_pkt(bool tx, uint8_t pkt_len, uint8_t pkt_data[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mp_printf(&mp_plat_print,
|
mp_printf(&mp_plat_print,
|
||||||
"handle: %04x, pb: %d, bc: %d, data_len: %d, ",
|
"handle: %04x, pb: %d, bc: %d, data_len: %d, ",
|
||||||
pkt->handle, pkt->pb, pkt->bc, pkt->data_len);
|
pkt->handle, pkt->pb, pkt->bc, pkt->data_len);
|
||||||
|
|
||||||
if (pkt->pb != ACL_DATA_PB_MIDDLE) {
|
if (pkt->pb != ACL_DATA_PB_MIDDLE) {
|
||||||
// This is the start of a fragmented acl_data packet or is a full packet.
|
// This is the start of a fragmented acl_data packet or is a full packet.
|
||||||
mp_printf(&mp_plat_print,
|
mp_printf(&mp_plat_print,
|
||||||
"acl data_len: %d, cid: %04x, data: ",
|
"acl data_len: %d, cid: %04x, data: ",
|
||||||
acl->acl_data_len, acl->cid);
|
acl->acl_data_len, acl->cid);
|
||||||
for (size_t i = 0; i < acl->acl_data_len; i++) {
|
for (size_t i = 0; i < acl->acl_data_len; i++) {
|
||||||
mp_printf(&mp_plat_print, "%02x ", acl->acl_data[i]);
|
mp_printf(&mp_plat_print, "%02x ", acl->acl_data[i]);
|
||||||
}
|
}
|
||||||
@ -316,15 +530,15 @@ STATIC void dump_acl_pkt(bool tx, uint8_t pkt_len, uint8_t pkt_data[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void dump_evt_pkt(bool tx, uint8_t pkt_len, uint8_t pkt_data[]) {
|
STATIC void dump_evt_pkt(bool tx, uint8_t pkt_len, uint8_t pkt_data[]) {
|
||||||
h4_hci_evt_pkt_t *pkt = (h4_hci_evt_pkt_t *) pkt_data;
|
h4_hci_evt_pkt_t *pkt = (h4_hci_evt_pkt_t *)pkt_data;
|
||||||
mp_printf(&mp_plat_print,
|
mp_printf(&mp_plat_print,
|
||||||
"%s HCI EVENT (%x) evt: %s (%02x), param_len: %d, data: ",
|
"%s HCI EVENT (%x) evt: %s (%02x), param_len: %d, data: ",
|
||||||
tx ? "TX->" : "RX<-",
|
tx ? "TX->" : "RX<-",
|
||||||
pkt->pkt_type,
|
pkt->pkt_type,
|
||||||
pkt->evt == BT_HCI_EVT_LE_META_EVENT
|
pkt->evt == BT_HCI_EVT_LE_META_EVENT
|
||||||
? hci_evt_le_name(pkt->params[0])
|
? hci_evt_le_name(pkt->params[0])
|
||||||
: hci_evt_name(pkt->evt),
|
: hci_evt_name(pkt->evt),
|
||||||
pkt->evt, pkt->param_len);
|
pkt->evt, pkt->param_len);
|
||||||
for (size_t i = 0; i < pkt->param_len; i++) {
|
for (size_t i = 0; i < pkt->param_len; i++) {
|
||||||
mp_printf(&mp_plat_print, "%02x ", pkt->params[i]);
|
mp_printf(&mp_plat_print, "%02x ", pkt->params[i]);
|
||||||
}
|
}
|
||||||
|
@ -29,40 +29,36 @@
|
|||||||
|
|
||||||
/** Bluetooth Device Address */
|
/** Bluetooth Device Address */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t val[6];
|
uint8_t val[6];
|
||||||
} bt_addr_t;
|
} bt_addr_t;
|
||||||
|
|
||||||
/** Bluetooth LE Device Address */
|
/** Bluetooth LE Device Address */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
bt_addr_t a;
|
bt_addr_t a;
|
||||||
} bt_addr_le_t;
|
} bt_addr_le_t;
|
||||||
|
|
||||||
#define BT_ADDR_ANY ((bt_addr_t[]) { { { 0, 0, 0, 0, 0, 0 } } })
|
#define BT_ADDR_ANY ((bt_addr_t[]) { { { 0, 0, 0, 0, 0, 0 } } })
|
||||||
#define BT_ADDR_NONE ((bt_addr_t[]) { { \
|
#define BT_ADDR_NONE ((bt_addr_t[]) { { \
|
||||||
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } })
|
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } })
|
||||||
#define BT_ADDR_LE_ANY ((bt_addr_le_t[]) { { 0, { { 0, 0, 0, 0, 0, 0 } } } })
|
#define BT_ADDR_LE_ANY ((bt_addr_le_t[]) { { 0, { { 0, 0, 0, 0, 0, 0 } } } })
|
||||||
#define BT_ADDR_LE_NONE ((bt_addr_le_t[]) { { 0, \
|
#define BT_ADDR_LE_NONE ((bt_addr_le_t[]) { { 0, \
|
||||||
{ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } } })
|
{ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } } })
|
||||||
|
|
||||||
static inline int bt_addr_cmp(const bt_addr_t *a, const bt_addr_t *b)
|
static inline int bt_addr_cmp(const bt_addr_t *a, const bt_addr_t *b) {
|
||||||
{
|
return memcmp(a, b, sizeof(*a));
|
||||||
return memcmp(a, b, sizeof(*a));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bt_addr_le_cmp(const bt_addr_le_t *a, const bt_addr_le_t *b)
|
static inline int bt_addr_le_cmp(const bt_addr_le_t *a, const bt_addr_le_t *b) {
|
||||||
{
|
return memcmp(a, b, sizeof(*a));
|
||||||
return memcmp(a, b, sizeof(*a));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bt_addr_copy(bt_addr_t *dst, const bt_addr_t *src)
|
static inline void bt_addr_copy(bt_addr_t *dst, const bt_addr_t *src) {
|
||||||
{
|
memcpy(dst, src, sizeof(*dst));
|
||||||
memcpy(dst, src, sizeof(*dst));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bt_addr_le_copy(bt_addr_le_t *dst, const bt_addr_le_t *src)
|
static inline void bt_addr_le_copy(bt_addr_le_t *dst, const bt_addr_le_t *src) {
|
||||||
{
|
memcpy(dst, src, sizeof(*dst));
|
||||||
memcpy(dst, src, sizeof(*dst));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BT_ADDR_IS_RPA(a) (((a)->val[5] & 0xc0) == 0x40)
|
#define BT_ADDR_IS_RPA(a) (((a)->val[5] & 0xc0) == 0x40)
|
||||||
@ -76,22 +72,20 @@ static inline void bt_addr_le_copy(bt_addr_le_t *dst, const bt_addr_le_t *src)
|
|||||||
int bt_addr_le_create_nrpa(bt_addr_le_t *addr);
|
int bt_addr_le_create_nrpa(bt_addr_le_t *addr);
|
||||||
int bt_addr_le_create_static(bt_addr_le_t *addr);
|
int bt_addr_le_create_static(bt_addr_le_t *addr);
|
||||||
|
|
||||||
static inline bool bt_addr_le_is_rpa(const bt_addr_le_t *addr)
|
static inline bool bt_addr_le_is_rpa(const bt_addr_le_t *addr) {
|
||||||
{
|
if (addr->type != BT_ADDR_LE_RANDOM) {
|
||||||
if (addr->type != BT_ADDR_LE_RANDOM) {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return BT_ADDR_IS_RPA(&addr->a);
|
return BT_ADDR_IS_RPA(&addr->a);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool bt_addr_le_is_identity(const bt_addr_le_t *addr)
|
static inline bool bt_addr_le_is_identity(const bt_addr_le_t *addr) {
|
||||||
{
|
if (addr->type == BT_ADDR_LE_PUBLIC) {
|
||||||
if (addr->type == BT_ADDR_LE_PUBLIC) {
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return BT_ADDR_IS_STATIC(&addr->a);
|
return BT_ADDR_IS_STATIC(&addr->a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,30 +12,30 @@
|
|||||||
#define ZEPHYR_INCLUDE_BLUETOOTH_ATT_H_
|
#define ZEPHYR_INCLUDE_BLUETOOTH_ATT_H_
|
||||||
|
|
||||||
/* Error codes for Error response PDU */
|
/* Error codes for Error response PDU */
|
||||||
#define BT_ATT_ERR_INVALID_HANDLE 0x01
|
#define BT_ATT_ERR_INVALID_HANDLE 0x01
|
||||||
#define BT_ATT_ERR_READ_NOT_PERMITTED 0x02
|
#define BT_ATT_ERR_READ_NOT_PERMITTED 0x02
|
||||||
#define BT_ATT_ERR_WRITE_NOT_PERMITTED 0x03
|
#define BT_ATT_ERR_WRITE_NOT_PERMITTED 0x03
|
||||||
#define BT_ATT_ERR_INVALID_PDU 0x04
|
#define BT_ATT_ERR_INVALID_PDU 0x04
|
||||||
#define BT_ATT_ERR_AUTHENTICATION 0x05
|
#define BT_ATT_ERR_AUTHENTICATION 0x05
|
||||||
#define BT_ATT_ERR_NOT_SUPPORTED 0x06
|
#define BT_ATT_ERR_NOT_SUPPORTED 0x06
|
||||||
#define BT_ATT_ERR_INVALID_OFFSET 0x07
|
#define BT_ATT_ERR_INVALID_OFFSET 0x07
|
||||||
#define BT_ATT_ERR_AUTHORIZATION 0x08
|
#define BT_ATT_ERR_AUTHORIZATION 0x08
|
||||||
#define BT_ATT_ERR_PREPARE_QUEUE_FULL 0x09
|
#define BT_ATT_ERR_PREPARE_QUEUE_FULL 0x09
|
||||||
#define BT_ATT_ERR_ATTRIBUTE_NOT_FOUND 0x0a
|
#define BT_ATT_ERR_ATTRIBUTE_NOT_FOUND 0x0a
|
||||||
#define BT_ATT_ERR_ATTRIBUTE_NOT_LONG 0x0b
|
#define BT_ATT_ERR_ATTRIBUTE_NOT_LONG 0x0b
|
||||||
#define BT_ATT_ERR_ENCRYPTION_KEY_SIZE 0x0c
|
#define BT_ATT_ERR_ENCRYPTION_KEY_SIZE 0x0c
|
||||||
#define BT_ATT_ERR_INVALID_ATTRIBUTE_LEN 0x0d
|
#define BT_ATT_ERR_INVALID_ATTRIBUTE_LEN 0x0d
|
||||||
#define BT_ATT_ERR_UNLIKELY 0x0e
|
#define BT_ATT_ERR_UNLIKELY 0x0e
|
||||||
#define BT_ATT_ERR_INSUFFICIENT_ENCRYPTION 0x0f
|
#define BT_ATT_ERR_INSUFFICIENT_ENCRYPTION 0x0f
|
||||||
#define BT_ATT_ERR_UNSUPPORTED_GROUP_TYPE 0x10
|
#define BT_ATT_ERR_UNSUPPORTED_GROUP_TYPE 0x10
|
||||||
#define BT_ATT_ERR_INSUFFICIENT_RESOURCES 0x11
|
#define BT_ATT_ERR_INSUFFICIENT_RESOURCES 0x11
|
||||||
#define BT_ATT_ERR_DB_OUT_OF_SYNC 0x12
|
#define BT_ATT_ERR_DB_OUT_OF_SYNC 0x12
|
||||||
#define BT_ATT_ERR_VALUE_NOT_ALLOWED 0x13
|
#define BT_ATT_ERR_VALUE_NOT_ALLOWED 0x13
|
||||||
|
|
||||||
/* Common Profile Error Codes (from CSS) */
|
/* Common Profile Error Codes (from CSS) */
|
||||||
#define BT_ATT_ERR_WRITE_REQ_REJECTED 0xfc
|
#define BT_ATT_ERR_WRITE_REQ_REJECTED 0xfc
|
||||||
#define BT_ATT_ERR_CCC_IMPROPER_CONF 0xfd
|
#define BT_ATT_ERR_CCC_IMPROPER_CONF 0xfd
|
||||||
#define BT_ATT_ERR_PROCEDURE_IN_PROGRESS 0xfe
|
#define BT_ATT_ERR_PROCEDURE_IN_PROGRESS 0xfe
|
||||||
#define BT_ATT_ERR_OUT_OF_RANGE 0xff
|
#define BT_ATT_ERR_OUT_OF_RANGE 0xff
|
||||||
|
|
||||||
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_ATT_H_ */
|
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_ATT_H_ */
|
||||||
|
@ -13,260 +13,260 @@
|
|||||||
// for __packed
|
// for __packed
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
#define BT_EATT_PSM 0x27
|
#define BT_EATT_PSM 0x27
|
||||||
#define BT_ATT_DEFAULT_LE_MTU 23
|
#define BT_ATT_DEFAULT_LE_MTU 23
|
||||||
#define BT_ATT_TIMEOUT K_SECONDS(30)
|
#define BT_ATT_TIMEOUT K_SECONDS(30)
|
||||||
|
|
||||||
//FIX #if BT_L2CAP_RX_MTU < CONFIG_BT_L2CAP_TX_MTU
|
// FIX #if BT_L2CAP_RX_MTU < CONFIG_BT_L2CAP_TX_MTU
|
||||||
// #define BT_ATT_MTU BT_L2CAP_RX_MTU
|
// #define BT_ATT_MTU BT_L2CAP_RX_MTU
|
||||||
// #else
|
// #else
|
||||||
// #define BT_ATT_MTU CONFIG_BT_L2CAP_TX_MTU
|
// #define BT_ATT_MTU CONFIG_BT_L2CAP_TX_MTU
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
struct bt_att_hdr {
|
struct bt_att_hdr {
|
||||||
uint8_t code;
|
uint8_t code;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_ATT_OP_ERROR_RSP 0x01
|
#define BT_ATT_OP_ERROR_RSP 0x01
|
||||||
struct bt_att_error_rsp {
|
struct bt_att_error_rsp {
|
||||||
uint8_t request;
|
uint8_t request;
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_ATT_OP_MTU_REQ 0x02
|
#define BT_ATT_OP_MTU_REQ 0x02
|
||||||
struct bt_att_exchange_mtu_req {
|
struct bt_att_exchange_mtu_req {
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_ATT_OP_MTU_RSP 0x03
|
#define BT_ATT_OP_MTU_RSP 0x03
|
||||||
struct bt_att_exchange_mtu_rsp {
|
struct bt_att_exchange_mtu_rsp {
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Find Information Request */
|
/* Find Information Request */
|
||||||
#define BT_ATT_OP_FIND_INFO_REQ 0x04
|
#define BT_ATT_OP_FIND_INFO_REQ 0x04
|
||||||
struct bt_att_find_info_req {
|
struct bt_att_find_info_req {
|
||||||
uint16_t start_handle;
|
uint16_t start_handle;
|
||||||
uint16_t end_handle;
|
uint16_t end_handle;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Format field values for BT_ATT_OP_FIND_INFO_RSP */
|
/* Format field values for BT_ATT_OP_FIND_INFO_RSP */
|
||||||
#define BT_ATT_INFO_16 0x01
|
#define BT_ATT_INFO_16 0x01
|
||||||
#define BT_ATT_INFO_128 0x02
|
#define BT_ATT_INFO_128 0x02
|
||||||
|
|
||||||
struct bt_att_info_16 {
|
struct bt_att_info_16 {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint16_t uuid;
|
uint16_t uuid;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_att_info_128 {
|
struct bt_att_info_128 {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint8_t uuid[16];
|
uint8_t uuid[16];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Find Information Response */
|
/* Find Information Response */
|
||||||
#define BT_ATT_OP_FIND_INFO_RSP 0x05
|
#define BT_ATT_OP_FIND_INFO_RSP 0x05
|
||||||
struct bt_att_find_info_rsp {
|
struct bt_att_find_info_rsp {
|
||||||
uint8_t format;
|
uint8_t format;
|
||||||
uint8_t info[];
|
uint8_t info[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Find By Type Value Request */
|
/* Find By Type Value Request */
|
||||||
#define BT_ATT_OP_FIND_TYPE_REQ 0x06
|
#define BT_ATT_OP_FIND_TYPE_REQ 0x06
|
||||||
struct bt_att_find_type_req {
|
struct bt_att_find_type_req {
|
||||||
uint16_t start_handle;
|
uint16_t start_handle;
|
||||||
uint16_t end_handle;
|
uint16_t end_handle;
|
||||||
uint16_t type;
|
uint16_t type;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_att_handle_group {
|
struct bt_att_handle_group {
|
||||||
uint16_t start_handle;
|
uint16_t start_handle;
|
||||||
uint16_t end_handle;
|
uint16_t end_handle;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Find By Type Value Response */
|
/* Find By Type Value Response */
|
||||||
#define BT_ATT_OP_FIND_TYPE_RSP 0x07
|
#define BT_ATT_OP_FIND_TYPE_RSP 0x07
|
||||||
struct bt_att_find_type_rsp {
|
struct bt_att_find_type_rsp {
|
||||||
uint8_t _dummy[0];
|
uint8_t _dummy[0];
|
||||||
struct bt_att_handle_group list[];
|
struct bt_att_handle_group list[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read By Type Request */
|
/* Read By Type Request */
|
||||||
#define BT_ATT_OP_READ_TYPE_REQ 0x08
|
#define BT_ATT_OP_READ_TYPE_REQ 0x08
|
||||||
struct bt_att_read_type_req {
|
struct bt_att_read_type_req {
|
||||||
uint16_t start_handle;
|
uint16_t start_handle;
|
||||||
uint16_t end_handle;
|
uint16_t end_handle;
|
||||||
uint8_t uuid[];
|
uint8_t uuid[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_att_data {
|
struct bt_att_data {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read By Type Response */
|
/* Read By Type Response */
|
||||||
#define BT_ATT_OP_READ_TYPE_RSP 0x09
|
#define BT_ATT_OP_READ_TYPE_RSP 0x09
|
||||||
struct bt_att_read_type_rsp {
|
struct bt_att_read_type_rsp {
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
struct bt_att_data data[];
|
struct bt_att_data data[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read Request */
|
/* Read Request */
|
||||||
#define BT_ATT_OP_READ_REQ 0x0a
|
#define BT_ATT_OP_READ_REQ 0x0a
|
||||||
struct bt_att_read_req {
|
struct bt_att_read_req {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read Response */
|
/* Read Response */
|
||||||
#define BT_ATT_OP_READ_RSP 0x0b
|
#define BT_ATT_OP_READ_RSP 0x0b
|
||||||
struct bt_att_read_rsp {
|
struct bt_att_read_rsp {
|
||||||
uint8_t _dummy[0];
|
uint8_t _dummy[0];
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read Blob Request */
|
/* Read Blob Request */
|
||||||
#define BT_ATT_OP_READ_BLOB_REQ 0x0c
|
#define BT_ATT_OP_READ_BLOB_REQ 0x0c
|
||||||
struct bt_att_read_blob_req {
|
struct bt_att_read_blob_req {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read Blob Response */
|
/* Read Blob Response */
|
||||||
#define BT_ATT_OP_READ_BLOB_RSP 0x0d
|
#define BT_ATT_OP_READ_BLOB_RSP 0x0d
|
||||||
struct bt_att_read_blob_rsp {
|
struct bt_att_read_blob_rsp {
|
||||||
uint8_t _dummy[0];
|
uint8_t _dummy[0];
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read Multiple Request */
|
/* Read Multiple Request */
|
||||||
#define BT_ATT_READ_MULT_MIN_LEN_REQ 0x04
|
#define BT_ATT_READ_MULT_MIN_LEN_REQ 0x04
|
||||||
|
|
||||||
#define BT_ATT_OP_READ_MULT_REQ 0x0e
|
#define BT_ATT_OP_READ_MULT_REQ 0x0e
|
||||||
struct bt_att_read_mult_req {
|
struct bt_att_read_mult_req {
|
||||||
uint8_t _dummy[0];
|
uint8_t _dummy[0];
|
||||||
uint16_t handles[];
|
uint16_t handles[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read Multiple Respose */
|
/* Read Multiple Respose */
|
||||||
#define BT_ATT_OP_READ_MULT_RSP 0x0f
|
#define BT_ATT_OP_READ_MULT_RSP 0x0f
|
||||||
struct bt_att_read_mult_rsp {
|
struct bt_att_read_mult_rsp {
|
||||||
uint8_t _dummy[0];
|
uint8_t _dummy[0];
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read by Group Type Request */
|
/* Read by Group Type Request */
|
||||||
#define BT_ATT_OP_READ_GROUP_REQ 0x10
|
#define BT_ATT_OP_READ_GROUP_REQ 0x10
|
||||||
struct bt_att_read_group_req {
|
struct bt_att_read_group_req {
|
||||||
uint16_t start_handle;
|
uint16_t start_handle;
|
||||||
uint16_t end_handle;
|
uint16_t end_handle;
|
||||||
uint8_t uuid[];
|
uint8_t uuid[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_att_group_data {
|
struct bt_att_group_data {
|
||||||
uint16_t start_handle;
|
uint16_t start_handle;
|
||||||
uint16_t end_handle;
|
uint16_t end_handle;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read by Group Type Response */
|
/* Read by Group Type Response */
|
||||||
#define BT_ATT_OP_READ_GROUP_RSP 0x11
|
#define BT_ATT_OP_READ_GROUP_RSP 0x11
|
||||||
struct bt_att_read_group_rsp {
|
struct bt_att_read_group_rsp {
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
struct bt_att_group_data data[];
|
struct bt_att_group_data data[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Write Request */
|
/* Write Request */
|
||||||
#define BT_ATT_OP_WRITE_REQ 0x12
|
#define BT_ATT_OP_WRITE_REQ 0x12
|
||||||
struct bt_att_write_req {
|
struct bt_att_write_req {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Write Response */
|
/* Write Response */
|
||||||
#define BT_ATT_OP_WRITE_RSP 0x13
|
#define BT_ATT_OP_WRITE_RSP 0x13
|
||||||
|
|
||||||
/* Prepare Write Request */
|
/* Prepare Write Request */
|
||||||
#define BT_ATT_OP_PREPARE_WRITE_REQ 0x16
|
#define BT_ATT_OP_PREPARE_WRITE_REQ 0x16
|
||||||
struct bt_att_prepare_write_req {
|
struct bt_att_prepare_write_req {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Prepare Write Respond */
|
/* Prepare Write Respond */
|
||||||
#define BT_ATT_OP_PREPARE_WRITE_RSP 0x17
|
#define BT_ATT_OP_PREPARE_WRITE_RSP 0x17
|
||||||
struct bt_att_prepare_write_rsp {
|
struct bt_att_prepare_write_rsp {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Execute Write Request */
|
/* Execute Write Request */
|
||||||
#define BT_ATT_FLAG_CANCEL 0x00
|
#define BT_ATT_FLAG_CANCEL 0x00
|
||||||
#define BT_ATT_FLAG_EXEC 0x01
|
#define BT_ATT_FLAG_EXEC 0x01
|
||||||
|
|
||||||
#define BT_ATT_OP_EXEC_WRITE_REQ 0x18
|
#define BT_ATT_OP_EXEC_WRITE_REQ 0x18
|
||||||
struct bt_att_exec_write_req {
|
struct bt_att_exec_write_req {
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Execute Write Response */
|
/* Execute Write Response */
|
||||||
#define BT_ATT_OP_EXEC_WRITE_RSP 0x19
|
#define BT_ATT_OP_EXEC_WRITE_RSP 0x19
|
||||||
|
|
||||||
/* Handle Value Notification */
|
/* Handle Value Notification */
|
||||||
#define BT_ATT_OP_NOTIFY 0x1b
|
#define BT_ATT_OP_NOTIFY 0x1b
|
||||||
struct bt_att_notify {
|
struct bt_att_notify {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Handle Value Indication */
|
/* Handle Value Indication */
|
||||||
#define BT_ATT_OP_INDICATE 0x1d
|
#define BT_ATT_OP_INDICATE 0x1d
|
||||||
struct bt_att_indicate {
|
struct bt_att_indicate {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Handle Value Confirm */
|
/* Handle Value Confirm */
|
||||||
#define BT_ATT_OP_CONFIRM 0x1e
|
#define BT_ATT_OP_CONFIRM 0x1e
|
||||||
|
|
||||||
struct bt_att_signature {
|
struct bt_att_signature {
|
||||||
uint8_t value[12];
|
uint8_t value[12];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_ATT_OP_READ_MULT_VL_REQ 0x20
|
#define BT_ATT_OP_READ_MULT_VL_REQ 0x20
|
||||||
struct bt_att_read_mult_vl_req {
|
struct bt_att_read_mult_vl_req {
|
||||||
uint8_t _dummy[0];
|
uint8_t _dummy[0];
|
||||||
uint16_t handles[];
|
uint16_t handles[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Read Multiple Respose */
|
/* Read Multiple Respose */
|
||||||
#define BT_ATT_OP_READ_MULT_VL_RSP 0x21
|
#define BT_ATT_OP_READ_MULT_VL_RSP 0x21
|
||||||
struct bt_att_read_mult_vl_rsp {
|
struct bt_att_read_mult_vl_rsp {
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Handle Multiple Value Notification */
|
/* Handle Multiple Value Notification */
|
||||||
#define BT_ATT_OP_NOTIFY_MULT 0x23
|
#define BT_ATT_OP_NOTIFY_MULT 0x23
|
||||||
struct bt_att_notify_mult {
|
struct bt_att_notify_mult {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Write Command */
|
/* Write Command */
|
||||||
#define BT_ATT_OP_WRITE_CMD 0x52
|
#define BT_ATT_OP_WRITE_CMD 0x52
|
||||||
struct bt_att_write_cmd {
|
struct bt_att_write_cmd {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Signed Write Command */
|
/* Signed Write Command */
|
||||||
#define BT_ATT_OP_SIGNED_WRITE_CMD 0xd2
|
#define BT_ATT_OP_SIGNED_WRITE_CMD 0xd2
|
||||||
struct bt_att_signed_write_cmd {
|
struct bt_att_signed_write_cmd {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint8_t value[];
|
uint8_t value[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -50,20 +50,20 @@ extern "C" {
|
|||||||
int bt_send(struct net_buf *buf);
|
int bt_send(struct net_buf *buf);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
/** Passthrough mode
|
/** Passthrough mode
|
||||||
*
|
*
|
||||||
* While in this mode the buffers are passed as is between the stack
|
* While in this mode the buffers are passed as is between the stack
|
||||||
* and the driver.
|
* and the driver.
|
||||||
*/
|
*/
|
||||||
BT_HCI_RAW_MODE_PASSTHROUGH = 0x00,
|
BT_HCI_RAW_MODE_PASSTHROUGH = 0x00,
|
||||||
|
|
||||||
/** H:4 mode
|
/** H:4 mode
|
||||||
*
|
*
|
||||||
* While in this mode H:4 headers will added into the buffers
|
* While in this mode H:4 headers will added into the buffers
|
||||||
* according to the buffer type when coming from the stack and will be
|
* according to the buffer type when coming from the stack and will be
|
||||||
* removed and used to set the buffer type.
|
* removed and used to set the buffer type.
|
||||||
*/
|
*/
|
||||||
BT_HCI_RAW_MODE_H4 = 0x01,
|
BT_HCI_RAW_MODE_H4 = 0x01,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Set Bluetooth RAW channel mode
|
/** @brief Set Bluetooth RAW channel mode
|
||||||
@ -93,31 +93,31 @@ uint8_t bt_hci_raw_get_mode(void);
|
|||||||
* @param _func Handler function to be called.
|
* @param _func Handler function to be called.
|
||||||
*/
|
*/
|
||||||
#define BT_HCI_RAW_CMD_EXT(_op, _min_len, _func) \
|
#define BT_HCI_RAW_CMD_EXT(_op, _min_len, _func) \
|
||||||
{ \
|
{ \
|
||||||
.op = _op, \
|
.op = _op, \
|
||||||
.min_len = _min_len, \
|
.min_len = _min_len, \
|
||||||
.func = _func, \
|
.func = _func, \
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bt_hci_raw_cmd_ext {
|
struct bt_hci_raw_cmd_ext {
|
||||||
/** Opcode of the command */
|
/** Opcode of the command */
|
||||||
uint16_t op;
|
uint16_t op;
|
||||||
|
|
||||||
/** Minimal length of the command */
|
/** Minimal length of the command */
|
||||||
size_t min_len;
|
size_t min_len;
|
||||||
|
|
||||||
/** Handler function.
|
/** Handler function.
|
||||||
*
|
*
|
||||||
* Handler function to be called when a command is intercepted.
|
* Handler function to be called when a command is intercepted.
|
||||||
*
|
*
|
||||||
* @param buf Buffer containing the command.
|
* @param buf Buffer containing the command.
|
||||||
*
|
*
|
||||||
* @return HCI Status code or BT_HCI_ERR_EXT_HANDLED if command has
|
* @return HCI Status code or BT_HCI_ERR_EXT_HANDLED if command has
|
||||||
* been handled already and a response has been sent as oppose to
|
* been handled already and a response has been sent as oppose to
|
||||||
* BT_HCI_ERR_SUCCESS which just indicates that the command can be
|
* BT_HCI_ERR_SUCCESS which just indicates that the command can be
|
||||||
* sent to the controller to be processed.
|
* sent to the controller to be processed.
|
||||||
*/
|
*/
|
||||||
uint8_t (*func)(struct net_buf *buf);
|
uint8_t (*func)(struct net_buf *buf);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Register Bluetooth RAW command extension table
|
/** @brief Register Bluetooth RAW command extension table
|
||||||
|
@ -32,11 +32,11 @@ extern "C" {
|
|||||||
#define BT_VS_CMD_BIT_READ_TX_POWER 14
|
#define BT_VS_CMD_BIT_READ_TX_POWER 14
|
||||||
|
|
||||||
#define BT_VS_CMD_SUP_FEAT(cmd) BT_LE_FEAT_TEST(cmd, \
|
#define BT_VS_CMD_SUP_FEAT(cmd) BT_LE_FEAT_TEST(cmd, \
|
||||||
BT_VS_CMD_BIT_SUP_FEAT)
|
BT_VS_CMD_BIT_SUP_FEAT)
|
||||||
#define BT_VS_CMD_READ_STATIC_ADDRS(cmd) BT_LE_FEAT_TEST(cmd, \
|
#define BT_VS_CMD_READ_STATIC_ADDRS(cmd) BT_LE_FEAT_TEST(cmd, \
|
||||||
BT_VS_CMD_BIT_READ_STATIC_ADDRS)
|
BT_VS_CMD_BIT_READ_STATIC_ADDRS)
|
||||||
#define BT_VS_CMD_READ_KEY_ROOTS(cmd) BT_LE_FEAT_TEST(cmd, \
|
#define BT_VS_CMD_READ_KEY_ROOTS(cmd) BT_LE_FEAT_TEST(cmd, \
|
||||||
BT_VS_CMD_BIT_READ_KEY_ROOTS)
|
BT_VS_CMD_BIT_READ_KEY_ROOTS)
|
||||||
|
|
||||||
#define BT_HCI_VS_HW_PLAT_INTEL 0x0001
|
#define BT_HCI_VS_HW_PLAT_INTEL 0x0001
|
||||||
#define BT_HCI_VS_HW_PLAT_NORDIC 0x0002
|
#define BT_HCI_VS_HW_PLAT_NORDIC 0x0002
|
||||||
@ -50,44 +50,44 @@ extern "C" {
|
|||||||
#define BT_HCI_VS_FW_VAR_VS_CTLR 0x0002
|
#define BT_HCI_VS_FW_VAR_VS_CTLR 0x0002
|
||||||
#define BT_HCI_VS_FW_VAR_FW_LOADER 0x0003
|
#define BT_HCI_VS_FW_VAR_FW_LOADER 0x0003
|
||||||
#define BT_HCI_VS_FW_VAR_RESCUE_IMG 0x0004
|
#define BT_HCI_VS_FW_VAR_RESCUE_IMG 0x0004
|
||||||
#define BT_HCI_OP_VS_READ_VERSION_INFO BT_OP(BT_OGF_VS, 0x0001)
|
#define BT_HCI_OP_VS_READ_VERSION_INFO BT_OP(BT_OGF_VS, 0x0001)
|
||||||
struct bt_hci_rp_vs_read_version_info {
|
struct bt_hci_rp_vs_read_version_info {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint16_t hw_platform;
|
uint16_t hw_platform;
|
||||||
uint16_t hw_variant;
|
uint16_t hw_variant;
|
||||||
uint8_t fw_variant;
|
uint8_t fw_variant;
|
||||||
uint8_t fw_version;
|
uint8_t fw_version;
|
||||||
uint16_t fw_revision;
|
uint16_t fw_revision;
|
||||||
uint32_t fw_build;
|
uint32_t fw_build;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OP_VS_READ_SUPPORTED_COMMANDS BT_OP(BT_OGF_VS, 0x0002)
|
#define BT_HCI_OP_VS_READ_SUPPORTED_COMMANDS BT_OP(BT_OGF_VS, 0x0002)
|
||||||
struct bt_hci_rp_vs_read_supported_commands {
|
struct bt_hci_rp_vs_read_supported_commands {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t commands[64];
|
uint8_t commands[64];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OP_VS_READ_SUPPORTED_FEATURES BT_OP(BT_OGF_VS, 0x0003)
|
#define BT_HCI_OP_VS_READ_SUPPORTED_FEATURES BT_OP(BT_OGF_VS, 0x0003)
|
||||||
struct bt_hci_rp_vs_read_supported_features {
|
struct bt_hci_rp_vs_read_supported_features {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t features[8];
|
uint8_t features[8];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OP_VS_SET_EVENT_MASK BT_OP(BT_OGF_VS, 0x0004)
|
#define BT_HCI_OP_VS_SET_EVENT_MASK BT_OP(BT_OGF_VS, 0x0004)
|
||||||
struct bt_hci_cp_vs_set_event_mask {
|
struct bt_hci_cp_vs_set_event_mask {
|
||||||
uint8_t event_mask[8];
|
uint8_t event_mask[8];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_VS_RESET_SOFT 0x00
|
#define BT_HCI_VS_RESET_SOFT 0x00
|
||||||
#define BT_HCI_VS_RESET_HARD 0x01
|
#define BT_HCI_VS_RESET_HARD 0x01
|
||||||
#define BT_HCI_OP_VS_RESET BT_OP(BT_OGF_VS, 0x0005)
|
#define BT_HCI_OP_VS_RESET BT_OP(BT_OGF_VS, 0x0005)
|
||||||
struct bt_hci_cp_vs_reset {
|
struct bt_hci_cp_vs_reset {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OP_VS_WRITE_BD_ADDR BT_OP(BT_OGF_VS, 0x0006)
|
#define BT_HCI_OP_VS_WRITE_BD_ADDR BT_OP(BT_OGF_VS, 0x0006)
|
||||||
struct bt_hci_cp_vs_write_bd_addr {
|
struct bt_hci_cp_vs_write_bd_addr {
|
||||||
bt_addr_t bdaddr;
|
bt_addr_t bdaddr;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_VS_TRACE_DISABLED 0x00
|
#define BT_HCI_VS_TRACE_DISABLED 0x00
|
||||||
@ -97,60 +97,60 @@ struct bt_hci_cp_vs_write_bd_addr {
|
|||||||
#define BT_HCI_VS_TRACE_VDC 0x01
|
#define BT_HCI_VS_TRACE_VDC 0x01
|
||||||
#define BT_HCI_OP_VS_SET_TRACE_ENABLE BT_OP(BT_OGF_VS, 0x0007)
|
#define BT_HCI_OP_VS_SET_TRACE_ENABLE BT_OP(BT_OGF_VS, 0x0007)
|
||||||
struct bt_hci_cp_vs_set_trace_enable {
|
struct bt_hci_cp_vs_set_trace_enable {
|
||||||
uint8_t enable;
|
uint8_t enable;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OP_VS_READ_BUILD_INFO BT_OP(BT_OGF_VS, 0x0008)
|
#define BT_HCI_OP_VS_READ_BUILD_INFO BT_OP(BT_OGF_VS, 0x0008)
|
||||||
struct bt_hci_rp_vs_read_build_info {
|
struct bt_hci_rp_vs_read_build_info {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t info[];
|
uint8_t info[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_hci_vs_static_addr {
|
struct bt_hci_vs_static_addr {
|
||||||
bt_addr_t bdaddr;
|
bt_addr_t bdaddr;
|
||||||
uint8_t ir[16];
|
uint8_t ir[16];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OP_VS_READ_STATIC_ADDRS BT_OP(BT_OGF_VS, 0x0009)
|
#define BT_HCI_OP_VS_READ_STATIC_ADDRS BT_OP(BT_OGF_VS, 0x0009)
|
||||||
struct bt_hci_rp_vs_read_static_addrs {
|
struct bt_hci_rp_vs_read_static_addrs {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t num_addrs;
|
uint8_t num_addrs;
|
||||||
struct bt_hci_vs_static_addr a[];
|
struct bt_hci_vs_static_addr a[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OP_VS_READ_KEY_HIERARCHY_ROOTS BT_OP(BT_OGF_VS, 0x000a)
|
#define BT_HCI_OP_VS_READ_KEY_HIERARCHY_ROOTS BT_OP(BT_OGF_VS, 0x000a)
|
||||||
struct bt_hci_rp_vs_read_key_hierarchy_roots {
|
struct bt_hci_rp_vs_read_key_hierarchy_roots {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t ir[16];
|
uint8_t ir[16];
|
||||||
uint8_t er[16];
|
uint8_t er[16];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OP_VS_READ_CHIP_TEMP BT_OP(BT_OGF_VS, 0x000b)
|
#define BT_HCI_OP_VS_READ_CHIP_TEMP BT_OP(BT_OGF_VS, 0x000b)
|
||||||
struct bt_hci_rp_vs_read_chip_temp {
|
struct bt_hci_rp_vs_read_chip_temp {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
int8_t temps;
|
int8_t temps;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_hci_vs_cmd {
|
struct bt_hci_vs_cmd {
|
||||||
uint16_t vendor_id;
|
uint16_t vendor_id;
|
||||||
uint16_t opcode_base;
|
uint16_t opcode_base;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_VS_VID_ANDROID 0x0001
|
#define BT_HCI_VS_VID_ANDROID 0x0001
|
||||||
#define BT_HCI_VS_VID_MICROSOFT 0x0002
|
#define BT_HCI_VS_VID_MICROSOFT 0x0002
|
||||||
#define BT_HCI_OP_VS_READ_HOST_STACK_CMDS BT_OP(BT_OGF_VS, 0x000c)
|
#define BT_HCI_OP_VS_READ_HOST_STACK_CMDS BT_OP(BT_OGF_VS, 0x000c)
|
||||||
struct bt_hci_rp_vs_read_host_stack_cmds {
|
struct bt_hci_rp_vs_read_host_stack_cmds {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t num_cmds;
|
uint8_t num_cmds;
|
||||||
struct bt_hci_vs_cmd c[];
|
struct bt_hci_vs_cmd c[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_VS_SCAN_REQ_REPORTS_DISABLED 0x00
|
#define BT_HCI_VS_SCAN_REQ_REPORTS_DISABLED 0x00
|
||||||
#define BT_HCI_VS_SCAN_REQ_REPORTS_ENABLED 0x01
|
#define BT_HCI_VS_SCAN_REQ_REPORTS_ENABLED 0x01
|
||||||
#define BT_HCI_OP_VS_SET_SCAN_REQ_REPORTS BT_OP(BT_OGF_VS, 0x000d)
|
#define BT_HCI_OP_VS_SET_SCAN_REQ_REPORTS BT_OP(BT_OGF_VS, 0x000d)
|
||||||
struct bt_hci_cp_vs_set_scan_req_reports {
|
struct bt_hci_cp_vs_set_scan_req_reports {
|
||||||
uint8_t enable;
|
uint8_t enable;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_VS_LL_HANDLE_TYPE_ADV 0x00
|
#define BT_HCI_VS_LL_HANDLE_TYPE_ADV 0x00
|
||||||
@ -159,37 +159,37 @@ struct bt_hci_cp_vs_set_scan_req_reports {
|
|||||||
#define BT_HCI_VS_LL_TX_POWER_LEVEL_NO_PREF 0x7F
|
#define BT_HCI_VS_LL_TX_POWER_LEVEL_NO_PREF 0x7F
|
||||||
#define BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL BT_OP(BT_OGF_VS, 0x000e)
|
#define BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL BT_OP(BT_OGF_VS, 0x000e)
|
||||||
struct bt_hci_cp_vs_write_tx_power_level {
|
struct bt_hci_cp_vs_write_tx_power_level {
|
||||||
uint8_t handle_type;
|
uint8_t handle_type;
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
int8_t tx_power_level;
|
int8_t tx_power_level;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_hci_rp_vs_write_tx_power_level {
|
struct bt_hci_rp_vs_write_tx_power_level {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t handle_type;
|
uint8_t handle_type;
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
int8_t selected_tx_power;
|
int8_t selected_tx_power;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OP_VS_READ_TX_POWER_LEVEL BT_OP(BT_OGF_VS, 0x000f)
|
#define BT_HCI_OP_VS_READ_TX_POWER_LEVEL BT_OP(BT_OGF_VS, 0x000f)
|
||||||
struct bt_hci_cp_vs_read_tx_power_level {
|
struct bt_hci_cp_vs_read_tx_power_level {
|
||||||
uint8_t handle_type;
|
uint8_t handle_type;
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_hci_rp_vs_read_tx_power_level {
|
struct bt_hci_rp_vs_read_tx_power_level {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t handle_type;
|
uint8_t handle_type;
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
int8_t tx_power_level;
|
int8_t tx_power_level;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OP_VS_READ_USB_TRANSPORT_MODE BT_OP(BT_OGF_VS, 0x0010)
|
#define BT_HCI_OP_VS_READ_USB_TRANSPORT_MODE BT_OP(BT_OGF_VS, 0x0010)
|
||||||
|
|
||||||
struct bt_hci_rp_vs_read_usb_transport_mode {
|
struct bt_hci_rp_vs_read_usb_transport_mode {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t num_supported_modes;
|
uint8_t num_supported_modes;
|
||||||
uint8_t supported_mode[];
|
uint8_t supported_mode[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_VS_USB_H2_MODE 0x00
|
#define BT_HCI_VS_USB_H2_MODE 0x00
|
||||||
@ -198,19 +198,19 @@ struct bt_hci_rp_vs_read_usb_transport_mode {
|
|||||||
#define BT_HCI_OP_VS_SET_USB_TRANSPORT_MODE BT_OP(BT_OGF_VS, 0x0011)
|
#define BT_HCI_OP_VS_SET_USB_TRANSPORT_MODE BT_OP(BT_OGF_VS, 0x0011)
|
||||||
|
|
||||||
struct bt_hci_cp_vs_set_usb_transport_mode {
|
struct bt_hci_cp_vs_set_usb_transport_mode {
|
||||||
uint8_t mode;
|
uint8_t mode;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Events */
|
/* Events */
|
||||||
|
|
||||||
struct bt_hci_evt_vs {
|
struct bt_hci_evt_vs {
|
||||||
uint8_t subevent;
|
uint8_t subevent;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_EVT_VS_FATAL_ERROR 0x02
|
#define BT_HCI_EVT_VS_FATAL_ERROR 0x02
|
||||||
struct bt_hci_evt_vs_fatal_error {
|
struct bt_hci_evt_vs_fatal_error {
|
||||||
uint64_t pc;
|
uint64_t pc;
|
||||||
uint8_t err_info[];
|
uint8_t err_info[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_VS_TRACE_LMP_TX 0x01
|
#define BT_HCI_VS_TRACE_LMP_TX 0x01
|
||||||
@ -220,14 +220,14 @@ struct bt_hci_evt_vs_fatal_error {
|
|||||||
#define BT_HCI_VS_TRACE_LE_CONN_IND 0x05
|
#define BT_HCI_VS_TRACE_LE_CONN_IND 0x05
|
||||||
#define BT_HCI_EVT_VS_TRACE_INFO 0x03
|
#define BT_HCI_EVT_VS_TRACE_INFO 0x03
|
||||||
struct bt_hci_evt_vs_trace_info {
|
struct bt_hci_evt_vs_trace_info {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint8_t data[];
|
uint8_t data[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_EVT_VS_SCAN_REQ_RX 0x04
|
#define BT_HCI_EVT_VS_SCAN_REQ_RX 0x04
|
||||||
struct bt_hci_evt_vs_scan_req_rx {
|
struct bt_hci_evt_vs_scan_req_rx {
|
||||||
bt_addr_le_t addr;
|
bt_addr_le_t addr;
|
||||||
int8_t rssi;
|
int8_t rssi;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Event mask bits */
|
/* Event mask bits */
|
||||||
@ -243,133 +243,133 @@ struct bt_hci_evt_vs_scan_req_rx {
|
|||||||
#define BT_HCI_MESH_EVT_PREFIX 0xF0
|
#define BT_HCI_MESH_EVT_PREFIX 0xF0
|
||||||
|
|
||||||
struct bt_hci_cp_mesh {
|
struct bt_hci_cp_mesh {
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OC_MESH_GET_OPTS 0x00
|
#define BT_HCI_OC_MESH_GET_OPTS 0x00
|
||||||
struct bt_hci_rp_mesh_get_opts {
|
struct bt_hci_rp_mesh_get_opts {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
uint8_t revision;
|
uint8_t revision;
|
||||||
uint8_t ch_map;
|
uint8_t ch_map;
|
||||||
int8_t min_tx_power;
|
int8_t min_tx_power;
|
||||||
int8_t max_tx_power;
|
int8_t max_tx_power;
|
||||||
uint8_t max_scan_filter;
|
uint8_t max_scan_filter;
|
||||||
uint8_t max_filter_pattern;
|
uint8_t max_filter_pattern;
|
||||||
uint8_t max_adv_slot;
|
uint8_t max_adv_slot;
|
||||||
uint8_t max_tx_window;
|
uint8_t max_tx_window;
|
||||||
uint8_t evt_prefix_len;
|
uint8_t evt_prefix_len;
|
||||||
uint8_t evt_prefix;
|
uint8_t evt_prefix;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_MESH_PATTERN_LEN_MAX 0x0f
|
#define BT_HCI_MESH_PATTERN_LEN_MAX 0x0f
|
||||||
|
|
||||||
#define BT_HCI_OC_MESH_SET_SCAN_FILTER 0x01
|
#define BT_HCI_OC_MESH_SET_SCAN_FILTER 0x01
|
||||||
struct bt_hci_mesh_pattern {
|
struct bt_hci_mesh_pattern {
|
||||||
uint8_t pattern_len;
|
uint8_t pattern_len;
|
||||||
uint8_t pattern[];
|
uint8_t pattern[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_hci_cp_mesh_set_scan_filter {
|
struct bt_hci_cp_mesh_set_scan_filter {
|
||||||
uint8_t scan_filter;
|
uint8_t scan_filter;
|
||||||
uint8_t filter_dup;
|
uint8_t filter_dup;
|
||||||
uint8_t num_patterns;
|
uint8_t num_patterns;
|
||||||
struct bt_hci_mesh_pattern patterns[];
|
struct bt_hci_mesh_pattern patterns[];
|
||||||
} __packed;
|
} __packed;
|
||||||
struct bt_hci_rp_mesh_set_scan_filter {
|
struct bt_hci_rp_mesh_set_scan_filter {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
uint8_t scan_filter;
|
uint8_t scan_filter;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OC_MESH_ADVERTISE 0x02
|
#define BT_HCI_OC_MESH_ADVERTISE 0x02
|
||||||
struct bt_hci_cp_mesh_advertise {
|
struct bt_hci_cp_mesh_advertise {
|
||||||
uint8_t adv_slot;
|
uint8_t adv_slot;
|
||||||
uint8_t own_addr_type;
|
uint8_t own_addr_type;
|
||||||
bt_addr_t random_addr;
|
bt_addr_t random_addr;
|
||||||
uint8_t ch_map;
|
uint8_t ch_map;
|
||||||
int8_t tx_power;
|
int8_t tx_power;
|
||||||
uint8_t min_tx_delay;
|
uint8_t min_tx_delay;
|
||||||
uint8_t max_tx_delay;
|
uint8_t max_tx_delay;
|
||||||
uint8_t retx_count;
|
uint8_t retx_count;
|
||||||
uint8_t retx_interval;
|
uint8_t retx_interval;
|
||||||
uint8_t scan_delay;
|
uint8_t scan_delay;
|
||||||
uint16_t scan_duration;
|
uint16_t scan_duration;
|
||||||
uint8_t scan_filter;
|
uint8_t scan_filter;
|
||||||
uint8_t data_len;
|
uint8_t data_len;
|
||||||
uint8_t data[31];
|
uint8_t data[31];
|
||||||
} __packed;
|
} __packed;
|
||||||
struct bt_hci_rp_mesh_advertise {
|
struct bt_hci_rp_mesh_advertise {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
uint8_t adv_slot;
|
uint8_t adv_slot;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OC_MESH_ADVERTISE_TIMED 0x03
|
#define BT_HCI_OC_MESH_ADVERTISE_TIMED 0x03
|
||||||
struct bt_hci_cp_mesh_advertise_timed {
|
struct bt_hci_cp_mesh_advertise_timed {
|
||||||
uint8_t adv_slot;
|
uint8_t adv_slot;
|
||||||
uint8_t own_addr_type;
|
uint8_t own_addr_type;
|
||||||
bt_addr_t random_addr;
|
bt_addr_t random_addr;
|
||||||
uint8_t ch_map;
|
uint8_t ch_map;
|
||||||
int8_t tx_power;
|
int8_t tx_power;
|
||||||
uint8_t retx_count;
|
uint8_t retx_count;
|
||||||
uint8_t retx_interval;
|
uint8_t retx_interval;
|
||||||
uint32_t instant;
|
uint32_t instant;
|
||||||
uint16_t tx_delay;
|
uint16_t tx_delay;
|
||||||
uint16_t tx_window;
|
uint16_t tx_window;
|
||||||
uint8_t data_len;
|
uint8_t data_len;
|
||||||
uint8_t data[31];
|
uint8_t data[31];
|
||||||
} __packed;
|
} __packed;
|
||||||
struct bt_hci_rp_mesh_advertise_timed {
|
struct bt_hci_rp_mesh_advertise_timed {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
uint8_t adv_slot;
|
uint8_t adv_slot;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OC_MESH_ADVERTISE_CANCEL 0x04
|
#define BT_HCI_OC_MESH_ADVERTISE_CANCEL 0x04
|
||||||
struct bt_hci_cp_mesh_advertise_cancel {
|
struct bt_hci_cp_mesh_advertise_cancel {
|
||||||
uint8_t adv_slot;
|
uint8_t adv_slot;
|
||||||
} __packed;
|
} __packed;
|
||||||
struct bt_hci_rp_mesh_advertise_cancel {
|
struct bt_hci_rp_mesh_advertise_cancel {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
uint8_t adv_slot;
|
uint8_t adv_slot;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_OC_MESH_SET_SCANNING 0x05
|
#define BT_HCI_OC_MESH_SET_SCANNING 0x05
|
||||||
struct bt_hci_cp_mesh_set_scanning {
|
struct bt_hci_cp_mesh_set_scanning {
|
||||||
uint8_t enable;
|
uint8_t enable;
|
||||||
uint8_t ch_map;
|
uint8_t ch_map;
|
||||||
uint8_t scan_filter;
|
uint8_t scan_filter;
|
||||||
} __packed;
|
} __packed;
|
||||||
struct bt_hci_rp_mesh_set_scanning {
|
struct bt_hci_rp_mesh_set_scanning {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Events */
|
/* Events */
|
||||||
struct bt_hci_evt_mesh {
|
struct bt_hci_evt_mesh {
|
||||||
uint8_t prefix;
|
uint8_t prefix;
|
||||||
uint8_t subevent;
|
uint8_t subevent;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_EVT_MESH_ADV_COMPLETE 0x00
|
#define BT_HCI_EVT_MESH_ADV_COMPLETE 0x00
|
||||||
struct bt_hci_evt_mesh_adv_complete {
|
struct bt_hci_evt_mesh_adv_complete {
|
||||||
uint8_t adv_slot;
|
uint8_t adv_slot;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_HCI_EVT_MESH_SCANNING_REPORT 0x01
|
#define BT_HCI_EVT_MESH_SCANNING_REPORT 0x01
|
||||||
struct bt_hci_evt_mesh_scan_report {
|
struct bt_hci_evt_mesh_scan_report {
|
||||||
bt_addr_le_t addr;
|
bt_addr_le_t addr;
|
||||||
uint8_t chan;
|
uint8_t chan;
|
||||||
int8_t rssi;
|
int8_t rssi;
|
||||||
uint32_t instant;
|
uint32_t instant;
|
||||||
uint8_t data_len;
|
uint8_t data_len;
|
||||||
uint8_t data[];
|
uint8_t data[];
|
||||||
} __packed;
|
} __packed;
|
||||||
struct bt_hci_evt_mesh_scanning_report {
|
struct bt_hci_evt_mesh_scanning_report {
|
||||||
uint8_t num_reports;
|
uint8_t num_reports;
|
||||||
struct bt_hci_evt_mesh_scan_report reports[];
|
struct bt_hci_evt_mesh_scan_report reports[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
enum l2cap_conn_list_action {
|
enum l2cap_conn_list_action {
|
||||||
BT_L2CAP_CHAN_LOOKUP,
|
BT_L2CAP_CHAN_LOOKUP,
|
||||||
BT_L2CAP_CHAN_DETACH,
|
BT_L2CAP_CHAN_DETACH,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BT_L2CAP_CID_BR_SIG 0x0001
|
#define BT_L2CAP_CID_BR_SIG 0x0001
|
||||||
@ -28,14 +28,14 @@ enum l2cap_conn_list_action {
|
|||||||
#define BT_L2CAP_PSM_RFCOMM 0x0003
|
#define BT_L2CAP_PSM_RFCOMM 0x0003
|
||||||
|
|
||||||
struct bt_l2cap_hdr {
|
struct bt_l2cap_hdr {
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint16_t cid;
|
uint16_t cid;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_l2cap_sig_hdr {
|
struct bt_l2cap_sig_hdr {
|
||||||
uint8_t code;
|
uint8_t code;
|
||||||
uint8_t ident;
|
uint8_t ident;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_REJ_NOT_UNDERSTOOD 0x0000
|
#define BT_L2CAP_REJ_NOT_UNDERSTOOD 0x0000
|
||||||
@ -44,19 +44,19 @@ struct bt_l2cap_sig_hdr {
|
|||||||
|
|
||||||
#define BT_L2CAP_CMD_REJECT 0x01
|
#define BT_L2CAP_CMD_REJECT 0x01
|
||||||
struct bt_l2cap_cmd_reject {
|
struct bt_l2cap_cmd_reject {
|
||||||
uint16_t reason;
|
uint16_t reason;
|
||||||
uint8_t data[];
|
uint8_t data[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct bt_l2cap_cmd_reject_cid_data {
|
struct bt_l2cap_cmd_reject_cid_data {
|
||||||
uint16_t scid;
|
uint16_t scid;
|
||||||
uint16_t dcid;
|
uint16_t dcid;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_CONN_REQ 0x02
|
#define BT_L2CAP_CONN_REQ 0x02
|
||||||
struct bt_l2cap_conn_req {
|
struct bt_l2cap_conn_req {
|
||||||
uint16_t psm;
|
uint16_t psm;
|
||||||
uint16_t scid;
|
uint16_t scid;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* command statuses in reposnse */
|
/* command statuses in reposnse */
|
||||||
@ -74,10 +74,10 @@ struct bt_l2cap_conn_req {
|
|||||||
|
|
||||||
#define BT_L2CAP_CONN_RSP 0x03
|
#define BT_L2CAP_CONN_RSP 0x03
|
||||||
struct bt_l2cap_conn_rsp {
|
struct bt_l2cap_conn_rsp {
|
||||||
uint16_t dcid;
|
uint16_t dcid;
|
||||||
uint16_t scid;
|
uint16_t scid;
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
uint16_t status;
|
uint16_t status;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_CONF_SUCCESS 0x0000
|
#define BT_L2CAP_CONF_SUCCESS 0x0000
|
||||||
@ -86,17 +86,17 @@ struct bt_l2cap_conn_rsp {
|
|||||||
|
|
||||||
#define BT_L2CAP_CONF_REQ 0x04
|
#define BT_L2CAP_CONF_REQ 0x04
|
||||||
struct bt_l2cap_conf_req {
|
struct bt_l2cap_conf_req {
|
||||||
uint16_t dcid;
|
uint16_t dcid;
|
||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
uint8_t data[];
|
uint8_t data[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_CONF_RSP 0x05
|
#define BT_L2CAP_CONF_RSP 0x05
|
||||||
struct bt_l2cap_conf_rsp {
|
struct bt_l2cap_conf_rsp {
|
||||||
uint16_t scid;
|
uint16_t scid;
|
||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
uint8_t data[];
|
uint8_t data[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Option type used by MTU config request data */
|
/* Option type used by MTU config request data */
|
||||||
@ -106,21 +106,21 @@ struct bt_l2cap_conf_rsp {
|
|||||||
#define BT_L2CAP_CONF_MASK 0x7f
|
#define BT_L2CAP_CONF_MASK 0x7f
|
||||||
|
|
||||||
struct bt_l2cap_conf_opt {
|
struct bt_l2cap_conf_opt {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
uint8_t data[];
|
uint8_t data[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_DISCONN_REQ 0x06
|
#define BT_L2CAP_DISCONN_REQ 0x06
|
||||||
struct bt_l2cap_disconn_req {
|
struct bt_l2cap_disconn_req {
|
||||||
uint16_t dcid;
|
uint16_t dcid;
|
||||||
uint16_t scid;
|
uint16_t scid;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_DISCONN_RSP 0x07
|
#define BT_L2CAP_DISCONN_RSP 0x07
|
||||||
struct bt_l2cap_disconn_rsp {
|
struct bt_l2cap_disconn_rsp {
|
||||||
uint16_t dcid;
|
uint16_t dcid;
|
||||||
uint16_t scid;
|
uint16_t scid;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_INFO_FEAT_MASK 0x0002
|
#define BT_L2CAP_INFO_FEAT_MASK 0x0002
|
||||||
@ -128,7 +128,7 @@ struct bt_l2cap_disconn_rsp {
|
|||||||
|
|
||||||
#define BT_L2CAP_INFO_REQ 0x0a
|
#define BT_L2CAP_INFO_REQ 0x0a
|
||||||
struct bt_l2cap_info_req {
|
struct bt_l2cap_info_req {
|
||||||
uint16_t type;
|
uint16_t type;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* info result */
|
/* info result */
|
||||||
@ -137,17 +137,17 @@ struct bt_l2cap_info_req {
|
|||||||
|
|
||||||
#define BT_L2CAP_INFO_RSP 0x0b
|
#define BT_L2CAP_INFO_RSP 0x0b
|
||||||
struct bt_l2cap_info_rsp {
|
struct bt_l2cap_info_rsp {
|
||||||
uint16_t type;
|
uint16_t type;
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
uint8_t data[];
|
uint8_t data[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_CONN_PARAM_REQ 0x12
|
#define BT_L2CAP_CONN_PARAM_REQ 0x12
|
||||||
struct bt_l2cap_conn_param_req {
|
struct bt_l2cap_conn_param_req {
|
||||||
uint16_t min_interval;
|
uint16_t min_interval;
|
||||||
uint16_t max_interval;
|
uint16_t max_interval;
|
||||||
uint16_t latency;
|
uint16_t latency;
|
||||||
uint16_t timeout;
|
uint16_t timeout;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_CONN_PARAM_ACCEPTED 0x0000
|
#define BT_L2CAP_CONN_PARAM_ACCEPTED 0x0000
|
||||||
@ -155,16 +155,16 @@ struct bt_l2cap_conn_param_req {
|
|||||||
|
|
||||||
#define BT_L2CAP_CONN_PARAM_RSP 0x13
|
#define BT_L2CAP_CONN_PARAM_RSP 0x13
|
||||||
struct bt_l2cap_conn_param_rsp {
|
struct bt_l2cap_conn_param_rsp {
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_LE_CONN_REQ 0x14
|
#define BT_L2CAP_LE_CONN_REQ 0x14
|
||||||
struct bt_l2cap_le_conn_req {
|
struct bt_l2cap_le_conn_req {
|
||||||
uint16_t psm;
|
uint16_t psm;
|
||||||
uint16_t scid;
|
uint16_t scid;
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
uint16_t mps;
|
uint16_t mps;
|
||||||
uint16_t credits;
|
uint16_t credits;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* valid results in conn response on LE */
|
/* valid results in conn response on LE */
|
||||||
@ -182,42 +182,42 @@ struct bt_l2cap_le_conn_req {
|
|||||||
|
|
||||||
#define BT_L2CAP_LE_CONN_RSP 0x15
|
#define BT_L2CAP_LE_CONN_RSP 0x15
|
||||||
struct bt_l2cap_le_conn_rsp {
|
struct bt_l2cap_le_conn_rsp {
|
||||||
uint16_t dcid;
|
uint16_t dcid;
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
uint16_t mps;
|
uint16_t mps;
|
||||||
uint16_t credits;
|
uint16_t credits;
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_LE_CREDITS 0x16
|
#define BT_L2CAP_LE_CREDITS 0x16
|
||||||
struct bt_l2cap_le_credits {
|
struct bt_l2cap_le_credits {
|
||||||
uint16_t cid;
|
uint16_t cid;
|
||||||
uint16_t credits;
|
uint16_t credits;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_ECRED_CONN_REQ 0x17
|
#define BT_L2CAP_ECRED_CONN_REQ 0x17
|
||||||
struct bt_l2cap_ecred_conn_req {
|
struct bt_l2cap_ecred_conn_req {
|
||||||
uint16_t psm;
|
uint16_t psm;
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
uint16_t mps;
|
uint16_t mps;
|
||||||
uint16_t credits;
|
uint16_t credits;
|
||||||
uint16_t scid[];
|
uint16_t scid[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_ECRED_CONN_RSP 0x18
|
#define BT_L2CAP_ECRED_CONN_RSP 0x18
|
||||||
struct bt_l2cap_ecred_conn_rsp {
|
struct bt_l2cap_ecred_conn_rsp {
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
uint16_t mps;
|
uint16_t mps;
|
||||||
uint16_t credits;
|
uint16_t credits;
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
uint16_t dcid[];
|
uint16_t dcid[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_ECRED_RECONF_REQ 0x19
|
#define BT_L2CAP_ECRED_RECONF_REQ 0x19
|
||||||
struct bt_l2cap_ecred_reconf_req {
|
struct bt_l2cap_ecred_reconf_req {
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
uint16_t mps;
|
uint16_t mps;
|
||||||
uint16_t scid[];
|
uint16_t scid[];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define BT_L2CAP_RECONF_SUCCESS 0x0000
|
#define BT_L2CAP_RECONF_SUCCESS 0x0000
|
||||||
@ -226,5 +226,5 @@ struct bt_l2cap_ecred_reconf_req {
|
|||||||
|
|
||||||
#define BT_L2CAP_ECRED_RECONF_RSP 0x1a
|
#define BT_L2CAP_ECRED_RECONF_RSP 0x1a
|
||||||
struct bt_l2cap_ecred_reconf_rsp {
|
struct bt_l2cap_ecred_reconf_rsp {
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
@ -57,7 +57,7 @@ STATIC void nibble_write(mp_soft_qspi_obj_t *self, uint8_t v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC int mp_soft_qspi_ioctl(void *self_in, uint32_t cmd) {
|
STATIC int mp_soft_qspi_ioctl(void *self_in, uint32_t cmd) {
|
||||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in;
|
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t *)self_in;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case MP_QSPI_IOCTL_INIT:
|
case MP_QSPI_IOCTL_INIT:
|
||||||
@ -67,7 +67,7 @@ STATIC int mp_soft_qspi_ioctl(void *self_in, uint32_t cmd) {
|
|||||||
// Configure pins
|
// Configure pins
|
||||||
mp_hal_pin_write(self->clk, 0);
|
mp_hal_pin_write(self->clk, 0);
|
||||||
mp_hal_pin_output(self->clk);
|
mp_hal_pin_output(self->clk);
|
||||||
//mp_hal_pin_write(self->clk, 1);
|
// mp_hal_pin_write(self->clk, 1);
|
||||||
mp_hal_pin_output(self->io0);
|
mp_hal_pin_output(self->io0);
|
||||||
mp_hal_pin_input(self->io1);
|
mp_hal_pin_input(self->io1);
|
||||||
mp_hal_pin_write(self->io2, 1);
|
mp_hal_pin_write(self->io2, 1);
|
||||||
@ -155,19 +155,19 @@ STATIC void mp_soft_qspi_qwrite(mp_soft_qspi_obj_t *self, size_t len, const uint
|
|||||||
SCK_LOW(self);
|
SCK_LOW(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
//mp_hal_pin_input(self->io1);
|
// mp_hal_pin_input(self->io1);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void mp_soft_qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) {
|
STATIC void mp_soft_qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) {
|
||||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in;
|
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t *)self_in;
|
||||||
uint32_t cmd_buf = cmd | data << 8;
|
uint32_t cmd_buf = cmd | data << 8;
|
||||||
CS_LOW(self);
|
CS_LOW(self);
|
||||||
mp_soft_qspi_transfer(self, 1 + len, (uint8_t*)&cmd_buf, NULL);
|
mp_soft_qspi_transfer(self, 1 + len, (uint8_t *)&cmd_buf, NULL);
|
||||||
CS_HIGH(self);
|
CS_HIGH(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void mp_soft_qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) {
|
STATIC void mp_soft_qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) {
|
||||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in;
|
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t *)self_in;
|
||||||
uint8_t cmd_buf[4] = {cmd, addr >> 16, addr >> 8, addr};
|
uint8_t cmd_buf[4] = {cmd, addr >> 16, addr >> 8, addr};
|
||||||
CS_LOW(self);
|
CS_LOW(self);
|
||||||
mp_soft_qspi_transfer(self, 4, cmd_buf, NULL);
|
mp_soft_qspi_transfer(self, 4, cmd_buf, NULL);
|
||||||
@ -176,16 +176,16 @@ STATIC void mp_soft_qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC uint32_t mp_soft_qspi_read_cmd(void *self_in, uint8_t cmd, size_t len) {
|
STATIC uint32_t mp_soft_qspi_read_cmd(void *self_in, uint8_t cmd, size_t len) {
|
||||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in;
|
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t *)self_in;
|
||||||
uint32_t cmd_buf = cmd;
|
uint32_t cmd_buf = cmd;
|
||||||
CS_LOW(self);
|
CS_LOW(self);
|
||||||
mp_soft_qspi_transfer(self, 1 + len, (uint8_t*)&cmd_buf, (uint8_t*)&cmd_buf);
|
mp_soft_qspi_transfer(self, 1 + len, (uint8_t *)&cmd_buf, (uint8_t *)&cmd_buf);
|
||||||
CS_HIGH(self);
|
CS_HIGH(self);
|
||||||
return cmd_buf >> 8;
|
return cmd_buf >> 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void mp_soft_qspi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) {
|
STATIC void mp_soft_qspi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) {
|
||||||
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in;
|
mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t *)self_in;
|
||||||
uint8_t cmd_buf[7] = {cmd, addr >> 16, addr >> 8, addr};
|
uint8_t cmd_buf[7] = {cmd, addr >> 16, addr >> 8, addr};
|
||||||
CS_LOW(self);
|
CS_LOW(self);
|
||||||
mp_soft_qspi_transfer(self, 1, cmd_buf, NULL);
|
mp_soft_qspi_transfer(self, 1, cmd_buf, NULL);
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include "drivers/bus/spi.h"
|
#include "drivers/bus/spi.h"
|
||||||
|
|
||||||
int mp_soft_spi_ioctl(void *self_in, uint32_t cmd) {
|
int mp_soft_spi_ioctl(void *self_in, uint32_t cmd) {
|
||||||
mp_soft_spi_obj_t *self = (mp_soft_spi_obj_t*)self_in;
|
mp_soft_spi_obj_t *self = (mp_soft_spi_obj_t *)self_in;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case MP_SPI_IOCTL_INIT:
|
case MP_SPI_IOCTL_INIT:
|
||||||
@ -45,7 +45,7 @@ int mp_soft_spi_ioctl(void *self_in, uint32_t cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mp_soft_spi_transfer(void *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
void mp_soft_spi_transfer(void *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||||
mp_soft_spi_obj_t *self = (mp_soft_spi_obj_t*)self_in;
|
mp_soft_spi_obj_t *self = (mp_soft_spi_obj_t *)self_in;
|
||||||
uint32_t delay_half = self->delay_half;
|
uint32_t delay_half = self->delay_half;
|
||||||
|
|
||||||
// only MSB transfer is implemented
|
// only MSB transfer is implemented
|
||||||
|
@ -50,9 +50,15 @@ STATIC mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t va
|
|||||||
uintptr_t addr = MICROPY_MACHINE_MEM_GET_READ_ADDR(index, self->elem_size);
|
uintptr_t addr = MICROPY_MACHINE_MEM_GET_READ_ADDR(index, self->elem_size);
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
switch (self->elem_size) {
|
switch (self->elem_size) {
|
||||||
case 1: val = (*(uint8_t*)addr); break;
|
case 1:
|
||||||
case 2: val = (*(uint16_t*)addr); break;
|
val = (*(uint8_t *)addr);
|
||||||
default: val = (*(uint32_t*)addr); break;
|
break;
|
||||||
|
case 2:
|
||||||
|
val = (*(uint16_t *)addr);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
val = (*(uint32_t *)addr);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return mp_obj_new_int(val);
|
return mp_obj_new_int(val);
|
||||||
} else {
|
} else {
|
||||||
@ -60,9 +66,15 @@ STATIC mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t va
|
|||||||
uintptr_t addr = MICROPY_MACHINE_MEM_GET_WRITE_ADDR(index, self->elem_size);
|
uintptr_t addr = MICROPY_MACHINE_MEM_GET_WRITE_ADDR(index, self->elem_size);
|
||||||
uint32_t val = mp_obj_get_int_truncated(value);
|
uint32_t val = mp_obj_get_int_truncated(value);
|
||||||
switch (self->elem_size) {
|
switch (self->elem_size) {
|
||||||
case 1: (*(uint8_t*)addr) = val; break;
|
case 1:
|
||||||
case 2: (*(uint16_t*)addr) = val; break;
|
(*(uint8_t *)addr) = val;
|
||||||
default: (*(uint32_t*)addr) = val; break;
|
break;
|
||||||
|
case 2:
|
||||||
|
(*(uint16_t *)addr) = val;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
(*(uint32_t *)addr) = val;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, const
|
|||||||
bool invert = false;
|
bool invert = false;
|
||||||
|
|
||||||
#if defined(MICROPY_PY_MACHINE_PIN_MAKE_NEW)
|
#if defined(MICROPY_PY_MACHINE_PIN_MAKE_NEW)
|
||||||
mp_pin_p_t *pin_p = (mp_pin_t*)mp_proto_get(QSTR_pin_protocol, pin);
|
mp_pin_p_t *pin_p = (mp_pin_t *)mp_proto_get(QSTR_pin_protocol, pin);
|
||||||
|
|
||||||
if (pin_p == NULL) {
|
if (pin_p == NULL) {
|
||||||
// If first argument isn't a Pin-like object, we filter out "invert"
|
// If first argument isn't a Pin-like object, we filter out "invert"
|
||||||
@ -64,8 +64,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, const
|
|||||||
pin = MICROPY_PY_MACHINE_PIN_MAKE_NEW(NULL, n_args, n_kw, pin_args);
|
pin = MICROPY_PY_MACHINE_PIN_MAKE_NEW(NULL, n_args, n_kw, pin_args);
|
||||||
|
|
||||||
mp_local_free(pin_args);
|
mp_local_free(pin_args);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
// Otherwise there should be 1 or 2 args
|
// Otherwise there should be 1 or 2 args
|
||||||
{
|
{
|
||||||
@ -154,7 +153,7 @@ const mp_obj_type_t machine_signal_type = {
|
|||||||
.make_new = signal_make_new,
|
.make_new = signal_make_new,
|
||||||
.call = signal_call,
|
.call = signal_call,
|
||||||
.protocol = &signal_pin_p,
|
.protocol = &signal_pin_p,
|
||||||
.locals_dict = (void*)&signal_locals_dict,
|
.locals_dict = (void *)&signal_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_MACHINE
|
#endif // MICROPY_PY_MACHINE
|
||||||
|
@ -34,9 +34,9 @@ typedef struct _mp_obj_btree_t {
|
|||||||
STATIC const mp_obj_type_t btree_type;
|
STATIC const mp_obj_type_t btree_type;
|
||||||
|
|
||||||
#define CHECK_ERROR(res) \
|
#define CHECK_ERROR(res) \
|
||||||
if (res == RET_ERROR) { \
|
if (res == RET_ERROR) { \
|
||||||
mp_raise_OSError(errno); \
|
mp_raise_OSError(errno); \
|
||||||
}
|
}
|
||||||
|
|
||||||
void __dbpanic(DB *db) {
|
void __dbpanic(DB *db) {
|
||||||
printf("__dbpanic(%p)\n", db);
|
printf("__dbpanic(%p)\n", db);
|
||||||
@ -74,8 +74,8 @@ STATIC mp_obj_t btree_put(size_t n_args, const mp_obj_t *args) {
|
|||||||
(void)n_args;
|
(void)n_args;
|
||||||
mp_obj_btree_t *self = MP_OBJ_TO_PTR(args[0]);
|
mp_obj_btree_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||||
DBT key, val;
|
DBT key, val;
|
||||||
key.data = (void*)mp_obj_str_get_data(args[1], &key.size);
|
key.data = (void *)mp_obj_str_get_data(args[1], &key.size);
|
||||||
val.data = (void*)mp_obj_str_get_data(args[2], &val.size);
|
val.data = (void *)mp_obj_str_get_data(args[2], &val.size);
|
||||||
return MP_OBJ_NEW_SMALL_INT(__bt_put(self->db, &key, &val, 0));
|
return MP_OBJ_NEW_SMALL_INT(__bt_put(self->db, &key, &val, 0));
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_put_obj, 3, 4, btree_put);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_put_obj, 3, 4, btree_put);
|
||||||
@ -83,7 +83,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_put_obj, 3, 4, btree_put);
|
|||||||
STATIC mp_obj_t btree_get(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t btree_get(size_t n_args, const mp_obj_t *args) {
|
||||||
mp_obj_btree_t *self = MP_OBJ_TO_PTR(args[0]);
|
mp_obj_btree_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||||
DBT key, val;
|
DBT key, val;
|
||||||
key.data = (void*)mp_obj_str_get_data(args[1], &key.size);
|
key.data = (void *)mp_obj_str_get_data(args[1], &key.size);
|
||||||
int res = __bt_get(self->db, &key, &val, 0);
|
int res = __bt_get(self->db, &key, &val, 0);
|
||||||
if (res == RET_SPECIAL) {
|
if (res == RET_SPECIAL) {
|
||||||
if (n_args > 2) {
|
if (n_args > 2) {
|
||||||
@ -102,7 +102,7 @@ STATIC mp_obj_t btree_seq(size_t n_args, const mp_obj_t *args) {
|
|||||||
int flags = MP_OBJ_SMALL_INT_VALUE(args[1]);
|
int flags = MP_OBJ_SMALL_INT_VALUE(args[1]);
|
||||||
DBT key, val;
|
DBT key, val;
|
||||||
if (n_args > 2) {
|
if (n_args > 2) {
|
||||||
key.data = (void*)mp_obj_str_get_data(args[2], &key.size);
|
key.data = (void *)mp_obj_str_get_data(args[2], &key.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int res = __bt_seq(self->db, &key, &val, flags);
|
int res = __bt_seq(self->db, &key, &val, flags);
|
||||||
@ -177,7 +177,7 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
|
|||||||
if (self->start_key != MP_OBJ_NULL) {
|
if (self->start_key != MP_OBJ_NULL) {
|
||||||
int flags = R_FIRST;
|
int flags = R_FIRST;
|
||||||
if (self->start_key != mp_const_none) {
|
if (self->start_key != mp_const_none) {
|
||||||
key.data = (void*)mp_obj_str_get_data(self->start_key, &key.size);
|
key.data = (void *)mp_obj_str_get_data(self->start_key, &key.size);
|
||||||
flags = R_CURSOR;
|
flags = R_CURSOR;
|
||||||
} else if (desc) {
|
} else if (desc) {
|
||||||
flags = R_LAST;
|
flags = R_LAST;
|
||||||
@ -195,7 +195,7 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
|
|||||||
|
|
||||||
if (self->end_key != mp_const_none) {
|
if (self->end_key != mp_const_none) {
|
||||||
DBT end_key;
|
DBT end_key;
|
||||||
end_key.data = (void*)mp_obj_str_get_data(self->end_key, &end_key.size);
|
end_key.data = (void *)mp_obj_str_get_data(self->end_key, &end_key.size);
|
||||||
BTREE *t = self->db->internal;
|
BTREE *t = self->db->internal;
|
||||||
int cmp = t->bt_cmp(&key, &end_key);
|
int cmp = t->bt_cmp(&key, &end_key);
|
||||||
if (desc) {
|
if (desc) {
|
||||||
@ -230,7 +230,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
|||||||
if (value == MP_OBJ_NULL) {
|
if (value == MP_OBJ_NULL) {
|
||||||
// delete
|
// delete
|
||||||
DBT key;
|
DBT key;
|
||||||
key.data = (void*)mp_obj_str_get_data(index, &key.size);
|
key.data = (void *)mp_obj_str_get_data(index, &key.size);
|
||||||
int res = __bt_delete(self->db, &key, 0);
|
int res = __bt_delete(self->db, &key, 0);
|
||||||
if (res == RET_SPECIAL) {
|
if (res == RET_SPECIAL) {
|
||||||
nlr_raise(mp_obj_new_exception(&mp_type_KeyError));
|
nlr_raise(mp_obj_new_exception(&mp_type_KeyError));
|
||||||
@ -240,7 +240,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
|||||||
} else if (value == MP_OBJ_SENTINEL) {
|
} else if (value == MP_OBJ_SENTINEL) {
|
||||||
// load
|
// load
|
||||||
DBT key, val;
|
DBT key, val;
|
||||||
key.data = (void*)mp_obj_str_get_data(index, &key.size);
|
key.data = (void *)mp_obj_str_get_data(index, &key.size);
|
||||||
int res = __bt_get(self->db, &key, &val, 0);
|
int res = __bt_get(self->db, &key, &val, 0);
|
||||||
if (res == RET_SPECIAL) {
|
if (res == RET_SPECIAL) {
|
||||||
nlr_raise(mp_obj_new_exception(&mp_type_KeyError));
|
nlr_raise(mp_obj_new_exception(&mp_type_KeyError));
|
||||||
@ -250,8 +250,8 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
|||||||
} else {
|
} else {
|
||||||
// store
|
// store
|
||||||
DBT key, val;
|
DBT key, val;
|
||||||
key.data = (void*)mp_obj_str_get_data(index, &key.size);
|
key.data = (void *)mp_obj_str_get_data(index, &key.size);
|
||||||
val.data = (void*)mp_obj_str_get_data(value, &val.size);
|
val.data = (void *)mp_obj_str_get_data(value, &val.size);
|
||||||
int res = __bt_put(self->db, &key, &val, 0);
|
int res = __bt_put(self->db, &key, &val, 0);
|
||||||
CHECK_ERROR(res);
|
CHECK_ERROR(res);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
@ -263,7 +263,7 @@ STATIC mp_obj_t btree_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs
|
|||||||
switch (op) {
|
switch (op) {
|
||||||
case MP_BINARY_OP_CONTAINS: {
|
case MP_BINARY_OP_CONTAINS: {
|
||||||
DBT key, val;
|
DBT key, val;
|
||||||
key.data = (void*)mp_obj_str_get_data(rhs_in, &key.size);
|
key.data = (void *)mp_obj_str_get_data(rhs_in, &key.size);
|
||||||
int res = __bt_get(self->db, &key, &val, 0);
|
int res = __bt_get(self->db, &key, &val, 0);
|
||||||
CHECK_ERROR(res);
|
CHECK_ERROR(res);
|
||||||
return mp_obj_new_bool(res != RET_SPECIAL);
|
return mp_obj_new_bool(res != RET_SPECIAL);
|
||||||
@ -296,7 +296,7 @@ STATIC const mp_obj_type_t btree_type = {
|
|||||||
.iternext = btree_iternext,
|
.iternext = btree_iternext,
|
||||||
.binary_op = btree_binary_op,
|
.binary_op = btree_binary_op,
|
||||||
.subscr = btree_subscr,
|
.subscr = btree_subscr,
|
||||||
.locals_dict = (void*)&btree_locals_dict,
|
.locals_dict = (void *)&btree_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC FILEVTABLE btree_stream_fvtable = {
|
STATIC FILEVTABLE btree_stream_fvtable = {
|
||||||
@ -324,14 +324,14 @@ STATIC mp_obj_t mod_btree_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
|||||||
mp_arg_val_t minkeypage;
|
mp_arg_val_t minkeypage;
|
||||||
} args;
|
} args;
|
||||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
|
||||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args);
|
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&args);
|
||||||
BTREEINFO openinfo = {0};
|
BTREEINFO openinfo = {0};
|
||||||
openinfo.flags = args.flags.u_int;
|
openinfo.flags = args.flags.u_int;
|
||||||
openinfo.cachesize = args.cachesize.u_int;
|
openinfo.cachesize = args.cachesize.u_int;
|
||||||
openinfo.psize = args.pagesize.u_int;
|
openinfo.psize = args.pagesize.u_int;
|
||||||
openinfo.minkeypage = args.minkeypage.u_int;
|
openinfo.minkeypage = args.minkeypage.u_int;
|
||||||
|
|
||||||
DB *db = __bt_open(pos_args[0], &btree_stream_fvtable, &openinfo, /*dflags*/0);
|
DB *db = __bt_open(pos_args[0], &btree_stream_fvtable, &openinfo, /*dflags*/ 0);
|
||||||
if (db == NULL) {
|
if (db == NULL) {
|
||||||
mp_raise_OSError(errno);
|
mp_raise_OSError(errno);
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_btree_globals, mp_module_btree_globals_tab
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_btree = {
|
const mp_obj_module_t mp_module_btree = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_btree_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_btree_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_BTREE
|
#endif // MICROPY_PY_BTREE
|
||||||
|
@ -22,8 +22,8 @@ typedef struct _mp_obj_framebuf_t {
|
|||||||
uint8_t format;
|
uint8_t format;
|
||||||
} mp_obj_framebuf_t;
|
} mp_obj_framebuf_t;
|
||||||
|
|
||||||
typedef void (*setpixel_t)(const mp_obj_framebuf_t*, int, int, uint32_t);
|
typedef void (*setpixel_t)(const mp_obj_framebuf_t *, int, int, uint32_t);
|
||||||
typedef uint32_t (*getpixel_t)(const mp_obj_framebuf_t*, int, int);
|
typedef uint32_t (*getpixel_t)(const mp_obj_framebuf_t *, int, int);
|
||||||
typedef void (*fill_rect_t)(const mp_obj_framebuf_t *, int, int, int, int, uint32_t);
|
typedef void (*fill_rect_t)(const mp_obj_framebuf_t *, int, int, int, int, uint32_t);
|
||||||
|
|
||||||
typedef struct _mp_framebuf_p_t {
|
typedef struct _mp_framebuf_p_t {
|
||||||
@ -47,20 +47,20 @@ typedef struct _mp_framebuf_p_t {
|
|||||||
STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||||
size_t index = (x + y * fb->stride) >> 3;
|
size_t index = (x + y * fb->stride) >> 3;
|
||||||
int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07);
|
int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07);
|
||||||
((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
|
((uint8_t *)fb->buf)[index] = (((uint8_t *)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC uint32_t mono_horiz_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
STATIC uint32_t mono_horiz_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||||
size_t index = (x + y * fb->stride) >> 3;
|
size_t index = (x + y * fb->stride) >> 3;
|
||||||
int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07);
|
int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07);
|
||||||
return (((uint8_t*)fb->buf)[index] >> (offset)) & 0x01;
|
return (((uint8_t *)fb->buf)[index] >> (offset)) & 0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||||
int reverse = fb->format == FRAMEBUF_MHMSB;
|
int reverse = fb->format == FRAMEBUF_MHMSB;
|
||||||
int advance = fb->stride >> 3;
|
int advance = fb->stride >> 3;
|
||||||
while (w--) {
|
while (w--) {
|
||||||
uint8_t *b = &((uint8_t*)fb->buf)[(x >> 3) + y * advance];
|
uint8_t *b = &((uint8_t *)fb->buf)[(x >> 3) + y * advance];
|
||||||
int offset = reverse ? x & 7 : 7 - (x & 7);
|
int offset = reverse ? x & 7 : 7 - (x & 7);
|
||||||
for (int hh = h; hh; --hh) {
|
for (int hh = h; hh; --hh) {
|
||||||
*b = (*b & ~(0x01 << offset)) | ((col != 0) << offset);
|
*b = (*b & ~(0x01 << offset)) | ((col != 0) << offset);
|
||||||
@ -75,16 +75,16 @@ STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int
|
|||||||
STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||||
size_t index = (y >> 3) * fb->stride + x;
|
size_t index = (y >> 3) * fb->stride + x;
|
||||||
uint8_t offset = y & 0x07;
|
uint8_t offset = y & 0x07;
|
||||||
((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
|
((uint8_t *)fb->buf)[index] = (((uint8_t *)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC uint32_t mvlsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
STATIC uint32_t mvlsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||||
return (((uint8_t*)fb->buf)[(y >> 3) * fb->stride + x] >> (y & 0x07)) & 0x01;
|
return (((uint8_t *)fb->buf)[(y >> 3) * fb->stride + x] >> (y & 0x07)) & 0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||||
while (h--) {
|
while (h--) {
|
||||||
uint8_t *b = &((uint8_t*)fb->buf)[(y >> 3) * fb->stride + x];
|
uint8_t *b = &((uint8_t *)fb->buf)[(y >> 3) * fb->stride + x];
|
||||||
uint8_t offset = y & 0x07;
|
uint8_t offset = y & 0x07;
|
||||||
for (int ww = w; ww; --ww) {
|
for (int ww = w; ww; --ww) {
|
||||||
*b = (*b & ~(0x01 << offset)) | ((col != 0) << offset);
|
*b = (*b & ~(0x01 << offset)) | ((col != 0) << offset);
|
||||||
@ -97,15 +97,15 @@ STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, in
|
|||||||
// Functions for RGB565 format
|
// Functions for RGB565 format
|
||||||
|
|
||||||
STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||||
((uint16_t*)fb->buf)[x + y * fb->stride] = col;
|
((uint16_t *)fb->buf)[x + y * fb->stride] = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC uint32_t rgb565_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
STATIC uint32_t rgb565_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||||
return ((uint16_t*)fb->buf)[x + y * fb->stride];
|
return ((uint16_t *)fb->buf)[x + y * fb->stride];
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||||
uint16_t *b = &((uint16_t*)fb->buf)[x + y * fb->stride];
|
uint16_t *b = &((uint16_t *)fb->buf)[x + y * fb->stride];
|
||||||
while (h--) {
|
while (h--) {
|
||||||
for (int ww = w; ww; --ww) {
|
for (int ww = w; ww; --ww) {
|
||||||
*b++ = col;
|
*b++ = col;
|
||||||
@ -117,7 +117,7 @@ STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, i
|
|||||||
// Functions for GS2_HMSB format
|
// Functions for GS2_HMSB format
|
||||||
|
|
||||||
STATIC void gs2_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
STATIC void gs2_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||||
uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 2];
|
uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 2];
|
||||||
uint8_t shift = (x & 0x3) << 1;
|
uint8_t shift = (x & 0x3) << 1;
|
||||||
uint8_t mask = 0x3 << shift;
|
uint8_t mask = 0x3 << shift;
|
||||||
uint8_t color = (col & 0x3) << shift;
|
uint8_t color = (col & 0x3) << shift;
|
||||||
@ -125,14 +125,14 @@ STATIC void gs2_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC uint32_t gs2_hmsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
STATIC uint32_t gs2_hmsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||||
uint8_t pixel = ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 2];
|
uint8_t pixel = ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 2];
|
||||||
uint8_t shift = (x & 0x3) << 1;
|
uint8_t shift = (x & 0x3) << 1;
|
||||||
return (pixel >> shift) & 0x3;
|
return (pixel >> shift) & 0x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void gs2_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
STATIC void gs2_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||||
for (int xx=x; xx < x+w; xx++) {
|
for (int xx = x; xx < x + w; xx++) {
|
||||||
for (int yy=y; yy < y+h; yy++) {
|
for (int yy = y; yy < y + h; yy++) {
|
||||||
gs2_hmsb_setpixel(fb, xx, yy, col);
|
gs2_hmsb_setpixel(fb, xx, yy, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ STATIC void gs2_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
|
|||||||
// Functions for GS4_HMSB format
|
// Functions for GS4_HMSB format
|
||||||
|
|
||||||
STATIC void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
STATIC void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||||
uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1];
|
uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1];
|
||||||
|
|
||||||
if (x % 2) {
|
if (x % 2) {
|
||||||
*pixel = ((uint8_t)col & 0x0f) | (*pixel & 0xf0);
|
*pixel = ((uint8_t)col & 0x0f) | (*pixel & 0xf0);
|
||||||
@ -152,15 +152,15 @@ STATIC void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_
|
|||||||
|
|
||||||
STATIC uint32_t gs4_hmsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
STATIC uint32_t gs4_hmsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||||
if (x % 2) {
|
if (x % 2) {
|
||||||
return ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1] & 0x0f;
|
return ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1] & 0x0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1] >> 4;
|
return ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1] >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||||
col &= 0x0f;
|
col &= 0x0f;
|
||||||
uint8_t *pixel_pair = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1];
|
uint8_t *pixel_pair = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1];
|
||||||
uint8_t col_shifted_left = col << 4;
|
uint8_t col_shifted_left = col << 4;
|
||||||
uint8_t col_pixel_pair = col_shifted_left | col;
|
uint8_t col_pixel_pair = col_shifted_left | col;
|
||||||
int pixel_count_till_next_line = (fb->stride - w) >> 1;
|
int pixel_count_till_next_line = (fb->stride - w) >> 1;
|
||||||
@ -192,16 +192,16 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
|
|||||||
// Functions for GS8 format
|
// Functions for GS8 format
|
||||||
|
|
||||||
STATIC void gs8_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
STATIC void gs8_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
|
||||||
uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride)];
|
uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride)];
|
||||||
*pixel = col & 0xff;
|
*pixel = col & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC uint32_t gs8_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
STATIC uint32_t gs8_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
|
||||||
return ((uint8_t*)fb->buf)[(x + y * fb->stride)];
|
return ((uint8_t *)fb->buf)[(x + y * fb->stride)];
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void gs8_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
STATIC void gs8_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
|
||||||
uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride)];
|
uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride)];
|
||||||
while (h--) {
|
while (h--) {
|
||||||
memset(pixel, col, w);
|
memset(pixel, col, w);
|
||||||
pixel += fb->stride;
|
pixel += fb->stride;
|
||||||
@ -287,7 +287,7 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, cons
|
|||||||
STATIC const mp_obj_type_t mp_type_framebuf;
|
STATIC const mp_obj_type_t mp_type_framebuf;
|
||||||
|
|
||||||
// Helper to ensure we have the native super class instead of a subclass.
|
// Helper to ensure we have the native super class instead of a subclass.
|
||||||
static mp_obj_framebuf_t* native_framebuf(mp_obj_t framebuf_obj) {
|
static mp_obj_framebuf_t *native_framebuf(mp_obj_t framebuf_obj) {
|
||||||
mp_obj_t native_framebuf = mp_instance_cast_to_native_base(framebuf_obj, &mp_type_framebuf);
|
mp_obj_t native_framebuf = mp_instance_cast_to_native_base(framebuf_obj, &mp_type_framebuf);
|
||||||
mp_obj_assert_native_inited(native_framebuf);
|
mp_obj_assert_native_inited(native_framebuf);
|
||||||
return MP_OBJ_TO_PTR(native_framebuf);
|
return MP_OBJ_TO_PTR(native_framebuf);
|
||||||
@ -384,9 +384,9 @@ STATIC mp_obj_t framebuf_rect(size_t n_args, const mp_obj_t *args) {
|
|||||||
mp_int_t col = mp_obj_get_int(args[5]);
|
mp_int_t col = mp_obj_get_int(args[5]);
|
||||||
|
|
||||||
fill_rect(self, x, y, w, 1, col);
|
fill_rect(self, x, y, w, 1, col);
|
||||||
fill_rect(self, x, y + h- 1, w, 1, col);
|
fill_rect(self, x, y + h - 1, w, 1, col);
|
||||||
fill_rect(self, x, y, 1, h, col);
|
fill_rect(self, x, y, 1, h, col);
|
||||||
fill_rect(self, x + w- 1, y, 1, h, col);
|
fill_rect(self, x + w - 1, y, 1, h, col);
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
@ -423,9 +423,15 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
|
|||||||
bool steep;
|
bool steep;
|
||||||
if (dy > dx) {
|
if (dy > dx) {
|
||||||
mp_int_t temp;
|
mp_int_t temp;
|
||||||
temp = x1; x1 = y1; y1 = temp;
|
temp = x1;
|
||||||
temp = dx; dx = dy; dy = temp;
|
x1 = y1;
|
||||||
temp = sx; sx = sy; sy = temp;
|
y1 = temp;
|
||||||
|
temp = dx;
|
||||||
|
dx = dy;
|
||||||
|
dy = temp;
|
||||||
|
temp = sx;
|
||||||
|
sx = sy;
|
||||||
|
sy = temp;
|
||||||
steep = true;
|
steep = true;
|
||||||
} else {
|
} else {
|
||||||
steep = false;
|
steep = false;
|
||||||
@ -473,7 +479,7 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
|
|||||||
(y >= self->height) ||
|
(y >= self->height) ||
|
||||||
(-x >= source->width) ||
|
(-x >= source->width) ||
|
||||||
(-y >= source->height)
|
(-y >= source->height)
|
||||||
) {
|
) {
|
||||||
// Out of bounds, no-op.
|
// Out of bounds, no-op.
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
@ -547,7 +553,7 @@ STATIC mp_obj_t framebuf_text(size_t n_args, const mp_obj_t *args) {
|
|||||||
// loop over chars
|
// loop over chars
|
||||||
for (; *str; ++str) {
|
for (; *str; ++str) {
|
||||||
// get char and make sure its in range of font
|
// get char and make sure its in range of font
|
||||||
int chr = *(uint8_t*)str;
|
int chr = *(uint8_t *)str;
|
||||||
if (chr < 32 || chr > 127) {
|
if (chr < 32 || chr > 127) {
|
||||||
chr = 127;
|
chr = 127;
|
||||||
}
|
}
|
||||||
@ -590,7 +596,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = {
|
|||||||
.name = MP_QSTR_FrameBuffer,
|
.name = MP_QSTR_FrameBuffer,
|
||||||
.make_new = framebuf_make_new,
|
.make_new = framebuf_make_new,
|
||||||
.buffer_p = { .get_buffer = framebuf_get_buffer },
|
.buffer_p = { .get_buffer = framebuf_get_buffer },
|
||||||
.locals_dict = (mp_obj_dict_t*)&framebuf_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&framebuf_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
// this factory function is provided for backwards compatibility with old FrameBuffer1 class
|
// this factory function is provided for backwards compatibility with old FrameBuffer1 class
|
||||||
@ -633,7 +639,7 @@ STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_tab
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_framebuf = {
|
const mp_obj_module_t mp_module_framebuf = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&framebuf_module_globals,
|
.globals = (mp_obj_dict_t *)&framebuf_module_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_FRAMEBUF
|
#endif // MICROPY_PY_FRAMEBUF
|
||||||
|
126
extmod/modlwip.c
126
extmod/modlwip.c
@ -19,7 +19,7 @@
|
|||||||
#include "lwip/init.h"
|
#include "lwip/init.h"
|
||||||
#include "lwip/tcp.h"
|
#include "lwip/tcp.h"
|
||||||
#include "lwip/udp.h"
|
#include "lwip/udp.h"
|
||||||
//#include "lwip/raw.h"
|
// #include "lwip/raw.h"
|
||||||
#include "lwip/dns.h"
|
#include "lwip/dns.h"
|
||||||
#include "lwip/igmp.h"
|
#include "lwip/igmp.h"
|
||||||
#if LWIP_VERSION_MAJOR < 2
|
#if LWIP_VERSION_MAJOR < 2
|
||||||
@ -71,7 +71,7 @@ void mod_lwip_register_poll(void (*poll)(void *arg), void *poll_arg);
|
|||||||
void mod_lwip_deregister_poll(void (*poll)(void *arg), void *poll_arg);
|
void mod_lwip_deregister_poll(void (*poll)(void *arg), void *poll_arg);
|
||||||
|
|
||||||
STATIC void slip_lwip_poll(void *netif) {
|
STATIC void slip_lwip_poll(void *netif) {
|
||||||
slipif_poll((struct netif*)netif);
|
slipif_poll((struct netif *)netif);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC const mp_obj_type_t lwip_slip_type;
|
STATIC const mp_obj_type_t lwip_slip_type;
|
||||||
@ -120,7 +120,7 @@ STATIC mp_obj_t lwip_slip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw,
|
|||||||
|
|
||||||
struct netif *n = &lwip_slip_obj.lwip_netif;
|
struct netif *n = &lwip_slip_obj.lwip_netif;
|
||||||
if (netif_add(n, &iplocal, IP_ADDR_BROADCAST, &ipremote, NULL, slipif_init, ip_input) == NULL) {
|
if (netif_add(n, &iplocal, IP_ADDR_BROADCAST, &ipremote, NULL, slipif_init, ip_input) == NULL) {
|
||||||
mp_raise_ValueError("out of memory");
|
mp_raise_ValueError("out of memory");
|
||||||
}
|
}
|
||||||
netif_set_up(n);
|
netif_set_up(n);
|
||||||
netif_set_default(n);
|
netif_set_default(n);
|
||||||
@ -146,7 +146,7 @@ STATIC const mp_obj_type_t lwip_slip_type = {
|
|||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
.name = MP_QSTR_slip,
|
.name = MP_QSTR_slip,
|
||||||
.make_new = lwip_slip_make_new,
|
.make_new = lwip_slip_make_new,
|
||||||
.locals_dict = (mp_obj_dict_t*)&lwip_slip_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&lwip_slip_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_LWIP_SLIP
|
#endif // MICROPY_PY_LWIP_SLIP
|
||||||
@ -158,7 +158,7 @@ STATIC const mp_obj_type_t lwip_slip_type = {
|
|||||||
// lwIP 2 changed LWIP_VERSION and it can no longer be used in macros,
|
// lwIP 2 changed LWIP_VERSION and it can no longer be used in macros,
|
||||||
// so we define our own equivalent version that can.
|
// so we define our own equivalent version that can.
|
||||||
#define LWIP_VERSION_MACRO (LWIP_VERSION_MAJOR << 24 | LWIP_VERSION_MINOR << 16 \
|
#define LWIP_VERSION_MACRO (LWIP_VERSION_MAJOR << 24 | LWIP_VERSION_MINOR << 16 \
|
||||||
| LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC)
|
| LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC)
|
||||||
|
|
||||||
// Extension to lwIP error codes
|
// Extension to lwIP error codes
|
||||||
#define _ERR_BADF -16
|
#define _ERR_BADF -16
|
||||||
@ -271,11 +271,11 @@ typedef struct _lwip_socket_obj_t {
|
|||||||
} lwip_socket_obj_t;
|
} lwip_socket_obj_t;
|
||||||
|
|
||||||
static inline void poll_sockets(void) {
|
static inline void poll_sockets(void) {
|
||||||
#ifdef MICROPY_EVENT_POLL_HOOK
|
#ifdef MICROPY_EVENT_POLL_HOOK
|
||||||
MICROPY_EVENT_POLL_HOOK;
|
MICROPY_EVENT_POLL_HOOK;
|
||||||
#else
|
#else
|
||||||
mp_hal_delay_ms(1);
|
mp_hal_delay_ms(1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
@ -295,7 +295,7 @@ STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
|||||||
STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||||
|
|
||||||
if (socket->incoming.pbuf != NULL) {
|
if (socket->incoming.pbuf != NULL) {
|
||||||
// That's why they call it "unreliable". No room in the inn, drop the packet.
|
// That's why they call it "unreliable". No room in the inn, drop the packet.
|
||||||
@ -309,7 +309,7 @@ STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
|||||||
|
|
||||||
// Callback for general tcp errors.
|
// Callback for general tcp errors.
|
||||||
STATIC void _lwip_tcp_error(void *arg, err_t err) {
|
STATIC void _lwip_tcp_error(void *arg, err_t err) {
|
||||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||||
|
|
||||||
// Pass the error code back via the connection variable.
|
// Pass the error code back via the connection variable.
|
||||||
socket->state = err;
|
socket->state = err;
|
||||||
@ -319,7 +319,7 @@ STATIC void _lwip_tcp_error(void *arg, err_t err) {
|
|||||||
|
|
||||||
// Callback for tcp connection requests. Error code err is unused. (See tcp.h)
|
// Callback for tcp connection requests. Error code err is unused. (See tcp.h)
|
||||||
STATIC err_t _lwip_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err) {
|
STATIC err_t _lwip_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err) {
|
||||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||||
|
|
||||||
socket->state = STATE_CONNECTED;
|
socket->state = STATE_CONNECTED;
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
@ -337,9 +337,8 @@ STATIC err_t _lwip_tcp_recv_unaccepted(void *arg, struct tcp_pcb *pcb, struct pb
|
|||||||
// "Poll" (idle) callback to be called ASAP after accept callback
|
// "Poll" (idle) callback to be called ASAP after accept callback
|
||||||
// to execute Python callback function, as it can't be executed
|
// to execute Python callback function, as it can't be executed
|
||||||
// from accept callback itself.
|
// from accept callback itself.
|
||||||
STATIC err_t _lwip_tcp_accept_finished(void *arg, struct tcp_pcb *pcb)
|
STATIC err_t _lwip_tcp_accept_finished(void *arg, struct tcp_pcb *pcb) {
|
||||||
{
|
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
|
||||||
tcp_poll(pcb, NULL, 0);
|
tcp_poll(pcb, NULL, 0);
|
||||||
exec_user_callback(socket);
|
exec_user_callback(socket);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
@ -347,7 +346,7 @@ STATIC err_t _lwip_tcp_accept_finished(void *arg, struct tcp_pcb *pcb)
|
|||||||
|
|
||||||
// Callback for incoming tcp connections.
|
// Callback for incoming tcp connections.
|
||||||
STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
|
STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
|
||||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||||
tcp_recv(newpcb, _lwip_tcp_recv_unaccepted);
|
tcp_recv(newpcb, _lwip_tcp_recv_unaccepted);
|
||||||
|
|
||||||
if (socket->incoming.connection != NULL) {
|
if (socket->incoming.connection != NULL) {
|
||||||
@ -369,7 +368,7 @@ STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
|
|||||||
|
|
||||||
// Callback for inbound tcp packets.
|
// Callback for inbound tcp packets.
|
||||||
STATIC err_t _lwip_tcp_recv(void *arg, struct tcp_pcb *tcpb, struct pbuf *p, err_t err) {
|
STATIC err_t _lwip_tcp_recv(void *arg, struct tcp_pcb *tcpb, struct pbuf *p, err_t err) {
|
||||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg;
|
||||||
|
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
// Other side has closed connection.
|
// Other side has closed connection.
|
||||||
@ -443,7 +442,9 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
|
|||||||
if (socket->timeout != -1) {
|
if (socket->timeout != -1) {
|
||||||
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
||||||
mp_hal_delay_ms(100);
|
mp_hal_delay_ms(100);
|
||||||
if (socket->incoming.pbuf != NULL) break;
|
if (socket->incoming.pbuf != NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (socket->incoming.pbuf == NULL) {
|
if (socket->incoming.pbuf == NULL) {
|
||||||
*_errno = MP_ETIMEDOUT;
|
*_errno = MP_ETIMEDOUT;
|
||||||
@ -467,16 +468,16 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
|
|||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
socket->incoming.pbuf = NULL;
|
socket->incoming.pbuf = NULL;
|
||||||
|
|
||||||
return (mp_uint_t) result;
|
return (mp_uint_t)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For use in stream virtual methods
|
// For use in stream virtual methods
|
||||||
#define STREAM_ERROR_CHECK(socket) \
|
#define STREAM_ERROR_CHECK(socket) \
|
||||||
if (socket->state < 0) { \
|
if (socket->state < 0) { \
|
||||||
*_errno = error_lookup_table[-socket->state]; \
|
*_errno = error_lookup_table[-socket->state]; \
|
||||||
return MP_STREAM_ERROR; \
|
return MP_STREAM_ERROR; \
|
||||||
} \
|
} \
|
||||||
assert(socket->pcb.tcp);
|
assert(socket->pcb.tcp);
|
||||||
|
|
||||||
|
|
||||||
// Helper function for send/sendto to handle TCP packets
|
// Helper function for send/sendto to handle TCP packets
|
||||||
@ -575,7 +576,7 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
|
|||||||
len = remaining;
|
len = remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf, (byte*)p->payload + socket->recv_offset, len);
|
memcpy(buf, (byte *)p->payload + socket->recv_offset, len);
|
||||||
|
|
||||||
remaining -= len;
|
remaining -= len;
|
||||||
if (remaining == 0) {
|
if (remaining == 0) {
|
||||||
@ -622,10 +623,15 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (socket->type) {
|
switch (socket->type) {
|
||||||
case MOD_NETWORK_SOCK_STREAM: socket->pcb.tcp = tcp_new(); break;
|
case MOD_NETWORK_SOCK_STREAM:
|
||||||
case MOD_NETWORK_SOCK_DGRAM: socket->pcb.udp = udp_new(); break;
|
socket->pcb.tcp = tcp_new();
|
||||||
//case MOD_NETWORK_SOCK_RAW: socket->pcb.raw = raw_new(); break;
|
break;
|
||||||
default: mp_raise_OSError(MP_EINVAL);
|
case MOD_NETWORK_SOCK_DGRAM:
|
||||||
|
socket->pcb.udp = udp_new();
|
||||||
|
break;
|
||||||
|
// case MOD_NETWORK_SOCK_RAW: socket->pcb.raw = raw_new(); break;
|
||||||
|
default:
|
||||||
|
mp_raise_OSError(MP_EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket->pcb.tcp == NULL) {
|
if (socket->pcb.tcp == NULL) {
|
||||||
@ -635,7 +641,7 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||||||
switch (socket->type) {
|
switch (socket->type) {
|
||||||
case MOD_NETWORK_SOCK_STREAM: {
|
case MOD_NETWORK_SOCK_STREAM: {
|
||||||
// Register the socket object as our callback argument.
|
// Register the socket object as our callback argument.
|
||||||
tcp_arg(socket->pcb.tcp, (void*)socket);
|
tcp_arg(socket->pcb.tcp, (void *)socket);
|
||||||
// Register our error callback.
|
// Register our error callback.
|
||||||
tcp_err(socket->pcb.tcp, _lwip_tcp_error);
|
tcp_err(socket->pcb.tcp, _lwip_tcp_error);
|
||||||
break;
|
break;
|
||||||
@ -643,7 +649,7 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||||||
case MOD_NETWORK_SOCK_DGRAM: {
|
case MOD_NETWORK_SOCK_DGRAM: {
|
||||||
// Register our receive callback now. Since UDP sockets don't require binding or connection
|
// Register our receive callback now. Since UDP sockets don't require binding or connection
|
||||||
// before use, there's no other good time to do it.
|
// before use, there's no other good time to do it.
|
||||||
udp_recv(socket->pcb.udp, _lwip_udp_incoming, (void*)socket);
|
udp_recv(socket->pcb.udp, _lwip_udp_incoming, (void *)socket);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -731,7 +737,9 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
|
|||||||
} else if (socket->timeout != -1) {
|
} else if (socket->timeout != -1) {
|
||||||
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
||||||
mp_hal_delay_ms(100);
|
mp_hal_delay_ms(100);
|
||||||
if (socket->incoming.connection != NULL) break;
|
if (socket->incoming.connection != NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (socket->incoming.connection == NULL) {
|
if (socket->incoming.connection == NULL) {
|
||||||
mp_raise_OSError(MP_ETIMEDOUT);
|
mp_raise_OSError(MP_ETIMEDOUT);
|
||||||
@ -759,7 +767,7 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
|
|||||||
socket2->state = STATE_CONNECTED;
|
socket2->state = STATE_CONNECTED;
|
||||||
socket2->recv_offset = 0;
|
socket2->recv_offset = 0;
|
||||||
socket2->callback = MP_OBJ_NULL;
|
socket2->callback = MP_OBJ_NULL;
|
||||||
tcp_arg(socket2->pcb.tcp, (void*)socket2);
|
tcp_arg(socket2->pcb.tcp, (void *)socket2);
|
||||||
tcp_err(socket2->pcb.tcp, _lwip_tcp_error);
|
tcp_err(socket2->pcb.tcp, _lwip_tcp_error);
|
||||||
tcp_recv(socket2->pcb.tcp, _lwip_tcp_recv);
|
tcp_recv(socket2->pcb.tcp, _lwip_tcp_recv);
|
||||||
|
|
||||||
@ -815,7 +823,9 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
|
|||||||
if (socket->timeout != -1) {
|
if (socket->timeout != -1) {
|
||||||
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
||||||
mp_hal_delay_ms(100);
|
mp_hal_delay_ms(100);
|
||||||
if (socket->state != STATE_CONNECTING) break;
|
if (socket->state != STATE_CONNECTING) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (socket->state == STATE_CONNECTING) {
|
if (socket->state == STATE_CONNECTING) {
|
||||||
mp_raise_OSError(MP_EINPROGRESS);
|
mp_raise_OSError(MP_EINPROGRESS);
|
||||||
@ -826,9 +836,9 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (socket->state == STATE_CONNECTED) {
|
if (socket->state == STATE_CONNECTED) {
|
||||||
err = ERR_OK;
|
err = ERR_OK;
|
||||||
} else {
|
} else {
|
||||||
err = socket->state;
|
err = socket->state;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -896,11 +906,11 @@ STATIC mp_obj_t lwip_socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
|
|||||||
mp_uint_t ret = 0;
|
mp_uint_t ret = 0;
|
||||||
switch (socket->type) {
|
switch (socket->type) {
|
||||||
case MOD_NETWORK_SOCK_STREAM: {
|
case MOD_NETWORK_SOCK_STREAM: {
|
||||||
ret = lwip_tcp_receive(socket, (byte*)vstr.buf, len, &_errno);
|
ret = lwip_tcp_receive(socket, (byte *)vstr.buf, len, &_errno);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MOD_NETWORK_SOCK_DGRAM: {
|
case MOD_NETWORK_SOCK_DGRAM: {
|
||||||
ret = lwip_udp_receive(socket, (byte*)vstr.buf, len, NULL, NULL, &_errno);
|
ret = lwip_udp_receive(socket, (byte *)vstr.buf, len, NULL, NULL, &_errno);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -963,12 +973,12 @@ STATIC mp_obj_t lwip_socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
|
|||||||
switch (socket->type) {
|
switch (socket->type) {
|
||||||
case MOD_NETWORK_SOCK_STREAM: {
|
case MOD_NETWORK_SOCK_STREAM: {
|
||||||
memcpy(ip, &socket->peer, sizeof(socket->peer));
|
memcpy(ip, &socket->peer, sizeof(socket->peer));
|
||||||
port = (mp_uint_t) socket->peer_port;
|
port = (mp_uint_t)socket->peer_port;
|
||||||
ret = lwip_tcp_receive(socket, (byte*)vstr.buf, len, &_errno);
|
ret = lwip_tcp_receive(socket, (byte *)vstr.buf, len, &_errno);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MOD_NETWORK_SOCK_DGRAM: {
|
case MOD_NETWORK_SOCK_DGRAM: {
|
||||||
ret = lwip_udp_receive(socket, (byte*)vstr.buf, len, ip, &port, &_errno);
|
ret = lwip_udp_receive(socket, (byte *)vstr.buf, len, ip, &port, &_errno);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1017,7 +1027,7 @@ STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
|
|||||||
mp_raise_OSError(_errno);
|
mp_raise_OSError(_errno);
|
||||||
}
|
}
|
||||||
bufinfo.len -= ret;
|
bufinfo.len -= ret;
|
||||||
bufinfo.buf = (char*)bufinfo.buf + ret;
|
bufinfo.buf = (char *)bufinfo.buf + ret;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1095,7 +1105,7 @@ STATIC mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa
|
// POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa
|
||||||
err_t err = igmp_joingroup((ip_addr_t*)bufinfo.buf + 1, bufinfo.buf);
|
err_t err = igmp_joingroup((ip_addr_t *)bufinfo.buf + 1, bufinfo.buf);
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
mp_raise_OSError(error_lookup_table[-err]);
|
mp_raise_OSError(error_lookup_table[-err]);
|
||||||
}
|
}
|
||||||
@ -1192,8 +1202,10 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MOD_NETWORK_SOCK_DGRAM: udp_remove(socket->pcb.udp); break;
|
case MOD_NETWORK_SOCK_DGRAM:
|
||||||
//case MOD_NETWORK_SOCK_RAW: raw_remove(socket->pcb.raw); break;
|
udp_remove(socket->pcb.udp);
|
||||||
|
break;
|
||||||
|
// case MOD_NETWORK_SOCK_RAW: raw_remove(socket->pcb.raw); break;
|
||||||
}
|
}
|
||||||
socket->pcb.tcp = NULL;
|
socket->pcb.tcp = NULL;
|
||||||
socket->state = _ERR_BADF;
|
socket->state = _ERR_BADF;
|
||||||
@ -1252,7 +1264,7 @@ STATIC const mp_obj_type_t lwip_socket_type = {
|
|||||||
.print = lwip_socket_print,
|
.print = lwip_socket_print,
|
||||||
.make_new = lwip_socket_make_new,
|
.make_new = lwip_socket_make_new,
|
||||||
.protocol = &lwip_socket_stream_p,
|
.protocol = &lwip_socket_stream_p,
|
||||||
.locals_dict = (mp_obj_dict_t*)&lwip_socket_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&lwip_socket_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -1272,18 +1284,18 @@ void sys_arch_unprotect(sys_prot_t state) {
|
|||||||
// itself a "list" but isn't; we only support a single interface.
|
// itself a "list" but isn't; we only support a single interface.
|
||||||
|
|
||||||
typedef struct nic_poll {
|
typedef struct nic_poll {
|
||||||
void (* poll)(void *arg);
|
void (*poll)(void *arg);
|
||||||
void *poll_arg;
|
void *poll_arg;
|
||||||
} nic_poll_t;
|
} nic_poll_t;
|
||||||
|
|
||||||
STATIC nic_poll_t lwip_poll_list;
|
STATIC nic_poll_t lwip_poll_list;
|
||||||
|
|
||||||
void mod_lwip_register_poll(void (* poll)(void *arg), void *poll_arg) {
|
void mod_lwip_register_poll(void (*poll)(void *arg), void *poll_arg) {
|
||||||
lwip_poll_list.poll = poll;
|
lwip_poll_list.poll = poll;
|
||||||
lwip_poll_list.poll_arg = poll_arg;
|
lwip_poll_list.poll_arg = poll_arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mod_lwip_deregister_poll(void (* poll)(void *arg), void *poll_arg) {
|
void mod_lwip_deregister_poll(void (*poll)(void *arg), void *poll_arg) {
|
||||||
lwip_poll_list.poll = NULL;
|
lwip_poll_list.poll = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1350,9 +1362,9 @@ STATIC mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!((family == 0 || family == MOD_NETWORK_AF_INET)
|
if (!((family == 0 || family == MOD_NETWORK_AF_INET)
|
||||||
&& (type == 0 || type == MOD_NETWORK_SOCK_STREAM)
|
&& (type == 0 || type == MOD_NETWORK_SOCK_STREAM)
|
||||||
&& proto == 0
|
&& proto == 0
|
||||||
&& flags == 0)) {
|
&& flags == 0)) {
|
||||||
mp_warning("unsupported getaddrinfo constraints");
|
mp_warning("unsupported getaddrinfo constraints");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1360,7 +1372,7 @@ STATIC mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
|||||||
getaddrinfo_state_t state;
|
getaddrinfo_state_t state;
|
||||||
state.status = 0;
|
state.status = 0;
|
||||||
|
|
||||||
err_t ret = dns_gethostbyname(host, (ip_addr_t*)&state.ipaddr, lwip_getaddrinfo_cb, &state);
|
err_t ret = dns_gethostbyname(host, (ip_addr_t *)&state.ipaddr, lwip_getaddrinfo_cb, &state);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case ERR_OK:
|
case ERR_OK:
|
||||||
// cached
|
// cached
|
||||||
@ -1386,8 +1398,8 @@ STATIC mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
|||||||
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM);
|
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM);
|
||||||
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0);
|
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0);
|
||||||
tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_);
|
tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_);
|
||||||
tuple->items[4] = netutils_format_inet_addr((uint8_t*)&state.ipaddr, port, NETUTILS_BIG);
|
tuple->items[4] = netutils_format_inet_addr((uint8_t *)&state.ipaddr, port, NETUTILS_BIG);
|
||||||
return mp_obj_new_list(1, (mp_obj_t*)&tuple);
|
return mp_obj_new_list(1, (mp_obj_t *)&tuple);
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_getaddrinfo_obj, 2, 6, lwip_getaddrinfo);
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_getaddrinfo_obj, 2, 6, lwip_getaddrinfo);
|
||||||
|
|
||||||
@ -1409,9 +1421,9 @@ STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_print_pcbs), MP_ROM_PTR(&lwip_print_pcbs_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_print_pcbs), MP_ROM_PTR(&lwip_print_pcbs_obj) },
|
||||||
// objects
|
// objects
|
||||||
{ MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&lwip_socket_type) },
|
{ MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&lwip_socket_type) },
|
||||||
#if MICROPY_PY_LWIP_SLIP
|
#if MICROPY_PY_LWIP_SLIP
|
||||||
{ MP_ROM_QSTR(MP_QSTR_slip), MP_ROM_PTR(&lwip_slip_type) },
|
{ MP_ROM_QSTR(MP_QSTR_slip), MP_ROM_PTR(&lwip_slip_type) },
|
||||||
#endif
|
#endif
|
||||||
// class constants
|
// class constants
|
||||||
{ MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(MOD_NETWORK_AF_INET) },
|
{ MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(MOD_NETWORK_AF_INET) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_AF_INET6), MP_ROM_INT(MOD_NETWORK_AF_INET6) },
|
{ MP_ROM_QSTR(MP_QSTR_AF_INET6), MP_ROM_INT(MOD_NETWORK_AF_INET6) },
|
||||||
@ -1431,7 +1443,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_lwip_globals, mp_module_lwip_globals_table
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_lwip = {
|
const mp_obj_module_t mp_module_lwip = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_lwip_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_lwip_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_LWIP
|
#endif // MICROPY_PY_LWIP
|
||||||
|
@ -105,7 +105,7 @@ STATIC mp_obj_t onewire_crc8(mp_obj_t data) {
|
|||||||
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
|
||||||
uint8_t crc = 0;
|
uint8_t crc = 0;
|
||||||
for (size_t i = 0; i < bufinfo.len; ++i) {
|
for (size_t i = 0; i < bufinfo.len; ++i) {
|
||||||
uint8_t byte = ((uint8_t*)bufinfo.buf)[i];
|
uint8_t byte = ((uint8_t *)bufinfo.buf)[i];
|
||||||
for (int b = 0; b < 8; ++b) {
|
for (int b = 0; b < 8; ++b) {
|
||||||
uint8_t fb_bit = (crc ^ byte) & 0x01;
|
uint8_t fb_bit = (crc ^ byte) & 0x01;
|
||||||
if (fb_bit == 0x01) {
|
if (fb_bit == 0x01) {
|
||||||
@ -137,5 +137,5 @@ STATIC MP_DEFINE_CONST_DICT(onewire_module_globals, onewire_module_globals_table
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_onewire = {
|
const mp_obj_module_t mp_module_onewire = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&onewire_module_globals,
|
.globals = (mp_obj_dict_t *)&onewire_module_globals,
|
||||||
};
|
};
|
||||||
|
@ -12,11 +12,11 @@
|
|||||||
#include "extmod/modubinascii.h"
|
#include "extmod/modubinascii.h"
|
||||||
|
|
||||||
static void check_not_unicode(const mp_obj_t arg) {
|
static void check_not_unicode(const mp_obj_t arg) {
|
||||||
#if MICROPY_CPYTHON_COMPAT
|
#if MICROPY_CPYTHON_COMPAT
|
||||||
if (MP_OBJ_IS_STR(arg)) {
|
if (MP_OBJ_IS_STR(arg)) {
|
||||||
mp_raise_TypeError(translate("a bytes-like object is required"));
|
mp_raise_TypeError(translate("a bytes-like object is required"));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args) {
|
mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args) {
|
||||||
@ -41,7 +41,7 @@ mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args) {
|
|||||||
sep = mp_obj_str_get_str(args[1]);
|
sep = mp_obj_str_get_str(args[1]);
|
||||||
}
|
}
|
||||||
vstr_init_len(&vstr, out_len);
|
vstr_init_len(&vstr, out_len);
|
||||||
byte *in = bufinfo.buf, *out = (byte*)vstr.buf;
|
byte *in = bufinfo.buf, *out = (byte *)vstr.buf;
|
||||||
for (mp_uint_t i = bufinfo.len; i--;) {
|
for (mp_uint_t i = bufinfo.len; i--;) {
|
||||||
byte d = (*in >> 4);
|
byte d = (*in >> 4);
|
||||||
if (d > 9) {
|
if (d > 9) {
|
||||||
@ -70,7 +70,7 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
|
|||||||
}
|
}
|
||||||
vstr_t vstr;
|
vstr_t vstr;
|
||||||
vstr_init_len(&vstr, bufinfo.len / 2);
|
vstr_init_len(&vstr, bufinfo.len / 2);
|
||||||
byte *in = bufinfo.buf, *out = (byte*)vstr.buf;
|
byte *in = bufinfo.buf, *out = (byte *)vstr.buf;
|
||||||
byte hex_byte = 0;
|
byte hex_byte = 0;
|
||||||
for (mp_uint_t i = bufinfo.len; i--;) {
|
for (mp_uint_t i = bufinfo.len; i--;) {
|
||||||
byte hex_ch = *in++;
|
byte hex_ch = *in++;
|
||||||
@ -161,7 +161,7 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
|
|||||||
vstr_init_len(&vstr, ((bufinfo.len != 0) ? (((bufinfo.len - 1) / 3) + 1) * 4 : 0) + 1);
|
vstr_init_len(&vstr, ((bufinfo.len != 0) ? (((bufinfo.len - 1) / 3) + 1) * 4 : 0) + 1);
|
||||||
|
|
||||||
// First pass, we convert input buffer to numeric base 64 values
|
// First pass, we convert input buffer to numeric base 64 values
|
||||||
byte *in = bufinfo.buf, *out = (byte*)vstr.buf;
|
byte *in = bufinfo.buf, *out = (byte *)vstr.buf;
|
||||||
mp_uint_t i;
|
mp_uint_t i;
|
||||||
for (i = bufinfo.len; i >= 3; i -= 3) {
|
for (i = bufinfo.len; i >= 3; i -= 3) {
|
||||||
*out++ = (in[0] & 0xFC) >> 2;
|
*out++ = (in[0] & 0xFC) >> 2;
|
||||||
@ -175,8 +175,7 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
|
|||||||
if (i == 2) {
|
if (i == 2) {
|
||||||
*out++ = (in[0] & 0x03) << 4 | (in[1] & 0xF0) >> 4;
|
*out++ = (in[0] & 0x03) << 4 | (in[1] & 0xF0) >> 4;
|
||||||
*out++ = (in[1] & 0x0F) << 2;
|
*out++ = (in[1] & 0x0F) << 2;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
*out++ = (in[0] & 0x03) << 4;
|
*out++ = (in[0] & 0x03) << 4;
|
||||||
*out++ = 64;
|
*out++ = 64;
|
||||||
}
|
}
|
||||||
@ -184,7 +183,7 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Second pass, we convert number base 64 values to actual base64 ascii encoding
|
// Second pass, we convert number base 64 values to actual base64 ascii encoding
|
||||||
out = (byte*)vstr.buf;
|
out = (byte *)vstr.buf;
|
||||||
for (mp_uint_t j = vstr.len - 1; j--;) {
|
for (mp_uint_t j = vstr.len - 1; j--;) {
|
||||||
if (*out < 26) {
|
if (*out < 26) {
|
||||||
*out += 'A';
|
*out += 'A';
|
||||||
@ -193,7 +192,7 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
|
|||||||
} else if (*out < 62) {
|
} else if (*out < 62) {
|
||||||
*out += '0' - 52;
|
*out += '0' - 52;
|
||||||
} else if (*out == 62) {
|
} else if (*out == 62) {
|
||||||
*out ='+';
|
*out = '+';
|
||||||
} else if (*out == 63) {
|
} else if (*out == 63) {
|
||||||
*out = '/';
|
*out = '/';
|
||||||
} else {
|
} else {
|
||||||
@ -237,7 +236,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globa
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_ubinascii = {
|
const mp_obj_module_t mp_module_ubinascii = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_binascii_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_binascii_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //MICROPY_PY_UBINASCII
|
#endif // MICROPY_PY_UBINASCII
|
||||||
|
@ -105,7 +105,7 @@ STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args
|
|||||||
mp_arg_check_num(n_args, kw_args, 2, 3, false);
|
mp_arg_check_num(n_args, kw_args, 2, 3, false);
|
||||||
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
|
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
|
||||||
o->base.type = type;
|
o->base.type = type;
|
||||||
o->addr = (void*)(uintptr_t)mp_obj_int_get_truncated(args[0]);
|
o->addr = (void *)(uintptr_t)mp_obj_int_get_truncated(args[0]);
|
||||||
o->desc = args[1];
|
o->desc = args[1];
|
||||||
o->flags = LAYOUT_NATIVE;
|
o->flags = LAYOUT_NATIVE;
|
||||||
if (n_args == 3) {
|
if (n_args == 3) {
|
||||||
@ -125,8 +125,12 @@ STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_p
|
|||||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
||||||
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||||
switch (agg_type) {
|
switch (agg_type) {
|
||||||
case PTR: typen = "PTR"; break;
|
case PTR:
|
||||||
case ARRAY: typen = "ARRAY"; break;
|
typen = "PTR";
|
||||||
|
break;
|
||||||
|
case ARRAY:
|
||||||
|
typen = "ARRAY";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
typen = "ERROR";
|
typen = "ERROR";
|
||||||
@ -157,10 +161,10 @@ STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_
|
|||||||
case STRUCT:
|
case STRUCT:
|
||||||
return uctypes_struct_size(t->items[1], layout_type, max_field_size);
|
return uctypes_struct_size(t->items[1], layout_type, max_field_size);
|
||||||
case PTR:
|
case PTR:
|
||||||
if (sizeof(void*) > *max_field_size) {
|
if (sizeof(void *) > *max_field_size) {
|
||||||
*max_field_size = sizeof(void*);
|
*max_field_size = sizeof(void *);
|
||||||
}
|
}
|
||||||
return sizeof(void*);
|
return sizeof(void *);
|
||||||
case ARRAY: {
|
case ARRAY: {
|
||||||
mp_int_t arr_sz = MP_OBJ_SMALL_INT_VALUE(t->items[1]);
|
mp_int_t arr_sz = MP_OBJ_SMALL_INT_VALUE(t->items[1]);
|
||||||
uint val_type = GET_TYPE(arr_sz, VAL_TYPE_BITS);
|
uint val_type = GET_TYPE(arr_sz, VAL_TYPE_BITS);
|
||||||
@ -189,7 +193,7 @@ STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_
|
|||||||
STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size) {
|
STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size) {
|
||||||
if (!MP_OBJ_IS_TYPE(desc_in, &mp_type_dict)) {
|
if (!MP_OBJ_IS_TYPE(desc_in, &mp_type_dict)) {
|
||||||
if (MP_OBJ_IS_TYPE(desc_in, &mp_type_tuple)) {
|
if (MP_OBJ_IS_TYPE(desc_in, &mp_type_tuple)) {
|
||||||
return uctypes_struct_agg_size((mp_obj_tuple_t*)MP_OBJ_TO_PTR(desc_in), layout_type, max_field_size);
|
return uctypes_struct_agg_size((mp_obj_tuple_t *)MP_OBJ_TO_PTR(desc_in), layout_type, max_field_size);
|
||||||
} else if (MP_OBJ_IS_SMALL_INT(desc_in)) {
|
} else if (MP_OBJ_IS_SMALL_INT(desc_in)) {
|
||||||
// We allow sizeof on both type definitions and structures/structure fields,
|
// We allow sizeof on both type definitions and structures/structure fields,
|
||||||
// but scalar structure field is lowered into native Python int, so all
|
// but scalar structure field is lowered into native Python int, so all
|
||||||
@ -276,11 +280,11 @@ static inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_
|
|||||||
static inline mp_uint_t get_aligned_basic(uint val_type, void *p) {
|
static inline mp_uint_t get_aligned_basic(uint val_type, void *p) {
|
||||||
switch (val_type) {
|
switch (val_type) {
|
||||||
case UINT8:
|
case UINT8:
|
||||||
return *(uint8_t*)p;
|
return *(uint8_t *)p;
|
||||||
case UINT16:
|
case UINT16:
|
||||||
return *(uint16_t*)p;
|
return *(uint16_t *)p;
|
||||||
case UINT32:
|
case UINT32:
|
||||||
return *(uint32_t*)p;
|
return *(uint32_t *)p;
|
||||||
}
|
}
|
||||||
assert(0);
|
assert(0);
|
||||||
return 0;
|
return 0;
|
||||||
@ -289,11 +293,14 @@ static inline mp_uint_t get_aligned_basic(uint val_type, void *p) {
|
|||||||
static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) {
|
static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) {
|
||||||
switch (val_type) {
|
switch (val_type) {
|
||||||
case UINT8:
|
case UINT8:
|
||||||
*(uint8_t*)p = (uint8_t)v; return;
|
*(uint8_t *)p = (uint8_t)v;
|
||||||
|
return;
|
||||||
case UINT16:
|
case UINT16:
|
||||||
*(uint16_t*)p = (uint16_t)v; return;
|
*(uint16_t *)p = (uint16_t)v;
|
||||||
|
return;
|
||||||
case UINT32:
|
case UINT32:
|
||||||
*(uint32_t*)p = (uint32_t)v; return;
|
*(uint32_t *)p = (uint32_t)v;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
@ -301,26 +308,26 @@ static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) {
|
|||||||
STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) {
|
STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) {
|
||||||
switch (val_type) {
|
switch (val_type) {
|
||||||
case UINT8:
|
case UINT8:
|
||||||
return MP_OBJ_NEW_SMALL_INT(((uint8_t*)p)[index]);
|
return MP_OBJ_NEW_SMALL_INT(((uint8_t *)p)[index]);
|
||||||
case INT8:
|
case INT8:
|
||||||
return MP_OBJ_NEW_SMALL_INT(((int8_t*)p)[index]);
|
return MP_OBJ_NEW_SMALL_INT(((int8_t *)p)[index]);
|
||||||
case UINT16:
|
case UINT16:
|
||||||
return MP_OBJ_NEW_SMALL_INT(((uint16_t*)p)[index]);
|
return MP_OBJ_NEW_SMALL_INT(((uint16_t *)p)[index]);
|
||||||
case INT16:
|
case INT16:
|
||||||
return MP_OBJ_NEW_SMALL_INT(((int16_t*)p)[index]);
|
return MP_OBJ_NEW_SMALL_INT(((int16_t *)p)[index]);
|
||||||
case UINT32:
|
case UINT32:
|
||||||
return mp_obj_new_int_from_uint(((uint32_t*)p)[index]);
|
return mp_obj_new_int_from_uint(((uint32_t *)p)[index]);
|
||||||
case INT32:
|
case INT32:
|
||||||
return mp_obj_new_int(((int32_t*)p)[index]);
|
return mp_obj_new_int(((int32_t *)p)[index]);
|
||||||
case UINT64:
|
case UINT64:
|
||||||
return mp_obj_new_int_from_ull(((uint64_t*)p)[index]);
|
return mp_obj_new_int_from_ull(((uint64_t *)p)[index]);
|
||||||
case INT64:
|
case INT64:
|
||||||
return mp_obj_new_int_from_ll(((int64_t*)p)[index]);
|
return mp_obj_new_int_from_ll(((int64_t *)p)[index]);
|
||||||
#if MICROPY_PY_BUILTINS_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
case FLOAT32:
|
case FLOAT32:
|
||||||
return mp_obj_new_float((mp_float_t)((float*)p)[index]);
|
return mp_obj_new_float((mp_float_t)((float *)p)[index]);
|
||||||
case FLOAT64:
|
case FLOAT64:
|
||||||
return mp_obj_new_float(((double*)p)[index]);
|
return mp_obj_new_float(((double *)p)[index]);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
@ -333,9 +340,9 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) {
|
|||||||
if (val_type == FLOAT32 || val_type == FLOAT64) {
|
if (val_type == FLOAT32 || val_type == FLOAT64) {
|
||||||
mp_float_t v = mp_obj_get_float(val);
|
mp_float_t v = mp_obj_get_float(val);
|
||||||
if (val_type == FLOAT32) {
|
if (val_type == FLOAT32) {
|
||||||
((float*)p)[index] = v;
|
((float *)p)[index] = v;
|
||||||
} else {
|
} else {
|
||||||
((double*)p)[index] = v;
|
((double *)p)[index] = v;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -343,21 +350,27 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) {
|
|||||||
mp_int_t v = mp_obj_get_int_truncated(val);
|
mp_int_t v = mp_obj_get_int_truncated(val);
|
||||||
switch (val_type) {
|
switch (val_type) {
|
||||||
case UINT8:
|
case UINT8:
|
||||||
((uint8_t*)p)[index] = (uint8_t)v; return;
|
((uint8_t *)p)[index] = (uint8_t)v;
|
||||||
|
return;
|
||||||
case INT8:
|
case INT8:
|
||||||
((int8_t*)p)[index] = (int8_t)v; return;
|
((int8_t *)p)[index] = (int8_t)v;
|
||||||
|
return;
|
||||||
case UINT16:
|
case UINT16:
|
||||||
((uint16_t*)p)[index] = (uint16_t)v; return;
|
((uint16_t *)p)[index] = (uint16_t)v;
|
||||||
|
return;
|
||||||
case INT16:
|
case INT16:
|
||||||
((int16_t*)p)[index] = (int16_t)v; return;
|
((int16_t *)p)[index] = (int16_t)v;
|
||||||
|
return;
|
||||||
case UINT32:
|
case UINT32:
|
||||||
((uint32_t*)p)[index] = (uint32_t)v; return;
|
((uint32_t *)p)[index] = (uint32_t)v;
|
||||||
|
return;
|
||||||
case INT32:
|
case INT32:
|
||||||
((int32_t*)p)[index] = (int32_t)v; return;
|
((int32_t *)p)[index] = (int32_t)v;
|
||||||
|
return;
|
||||||
case INT64:
|
case INT64:
|
||||||
case UINT64:
|
case UINT64:
|
||||||
if (sizeof(mp_int_t) == 8) {
|
if (sizeof(mp_int_t) == 8) {
|
||||||
((uint64_t*)p)[index] = (uint64_t)v;
|
((uint64_t *)p)[index] = (uint64_t)v;
|
||||||
} else {
|
} else {
|
||||||
// TODO: Doesn't offer atomic store semantics, but should at least try
|
// TODO: Doesn't offer atomic store semantics, but should at least try
|
||||||
set_unaligned(val_type, p, MP_ENDIANNESS_BIG, val);
|
set_unaligned(val_type, p, MP_ENDIANNESS_BIG, val);
|
||||||
@ -373,7 +386,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
|||||||
|
|
||||||
// TODO: Support at least OrderedDict in addition
|
// TODO: Support at least OrderedDict in addition
|
||||||
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)) {
|
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)) {
|
||||||
mp_raise_TypeError(translate("struct: no fields"));
|
mp_raise_TypeError(translate("struct: no fields"));
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr));
|
mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr));
|
||||||
@ -381,7 +394,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
|||||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(deref);
|
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(deref);
|
||||||
mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS);
|
mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS);
|
||||||
offset &= VALUE_MASK(VAL_TYPE_BITS);
|
offset &= VALUE_MASK(VAL_TYPE_BITS);
|
||||||
//printf("scalar type=%d offset=%x\n", val_type, offset);
|
// printf("scalar type=%d offset=%x\n", val_type, offset);
|
||||||
|
|
||||||
if (val_type <= INT64 || val_type == FLOAT32 || val_type == FLOAT64) {
|
if (val_type <= INT64 || val_type == FLOAT32 || val_type == FLOAT64) {
|
||||||
// printf("size=%d\n", GET_SCALAR_SIZE(val_type));
|
// printf("size=%d\n", GET_SCALAR_SIZE(val_type));
|
||||||
@ -451,7 +464,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
|||||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(sub->items[0]);
|
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(sub->items[0]);
|
||||||
mp_uint_t agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
mp_uint_t agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||||
offset &= VALUE_MASK(AGG_TYPE_BITS);
|
offset &= VALUE_MASK(AGG_TYPE_BITS);
|
||||||
//printf("agg type=%d offset=%x\n", agg_type, offset);
|
// printf("agg type=%d offset=%x\n", agg_type, offset);
|
||||||
|
|
||||||
switch (agg_type) {
|
switch (agg_type) {
|
||||||
case STRUCT: {
|
case STRUCT: {
|
||||||
@ -475,7 +488,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
|||||||
o->desc = MP_OBJ_FROM_PTR(sub);
|
o->desc = MP_OBJ_FROM_PTR(sub);
|
||||||
o->addr = self->addr + offset;
|
o->addr = self->addr + offset;
|
||||||
o->flags = self->flags;
|
o->flags = self->flags;
|
||||||
//printf("PTR/ARR base addr=%p\n", o->addr);
|
// printf("PTR/ARR base addr=%p\n", o->addr);
|
||||||
return MP_OBJ_FROM_PTR(o);
|
return MP_OBJ_FROM_PTR(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -555,7 +568,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t base_in, mp_obj_t index_in, mp_ob
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (agg_type == PTR) {
|
} else if (agg_type == PTR) {
|
||||||
byte *p = *(void**)self->addr;
|
byte *p = *(void **)self->addr;
|
||||||
if (MP_OBJ_IS_SMALL_INT(t->items[1])) {
|
if (MP_OBJ_IS_SMALL_INT(t->items[1])) {
|
||||||
uint val_type = GET_TYPE(MP_OBJ_SMALL_INT_VALUE(t->items[1]), VAL_TYPE_BITS);
|
uint val_type = GET_TYPE(MP_OBJ_SMALL_INT_VALUE(t->items[1]), VAL_TYPE_BITS);
|
||||||
return get_aligned(val_type, p, index);
|
return get_aligned(val_type, p, index);
|
||||||
@ -603,7 +616,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof
|
|||||||
/// captured by reference (and thus memory pointed by bytearray may change
|
/// captured by reference (and thus memory pointed by bytearray may change
|
||||||
/// or become invalid at later time). Use bytes_at() to capture by value.
|
/// or become invalid at later time). Use bytes_at() to capture by value.
|
||||||
STATIC mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) {
|
STATIC mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) {
|
||||||
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)(uintptr_t)mp_obj_int_get_truncated(ptr));
|
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void *)(uintptr_t)mp_obj_int_get_truncated(ptr));
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at);
|
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at);
|
||||||
|
|
||||||
@ -612,7 +625,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytear
|
|||||||
/// captured by value, i.e. copied. Use bytearray_at() to capture by reference
|
/// captured by value, i.e. copied. Use bytearray_at() to capture by reference
|
||||||
/// ("zero copy").
|
/// ("zero copy").
|
||||||
STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) {
|
STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) {
|
||||||
return mp_obj_new_bytes((void*)(uintptr_t)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size));
|
return mp_obj_new_bytes((void *)(uintptr_t)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size));
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at);
|
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at);
|
||||||
|
|
||||||
@ -690,7 +703,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uctypes_globals, mp_module_uctypes_globals
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_uctypes = {
|
const mp_obj_module_t mp_module_uctypes = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_uctypes_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_uctypes_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -49,8 +49,8 @@ STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_arg
|
|||||||
mp_arg_check_num(n_args, kw_args, 0, 1, false);
|
mp_arg_check_num(n_args, kw_args, 0, 1, false);
|
||||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context));
|
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context));
|
||||||
o->base.type = type;
|
o->base.type = type;
|
||||||
mbedtls_sha256_init((mbedtls_sha256_context*)&o->state);
|
mbedtls_sha256_init((mbedtls_sha256_context *)&o->state);
|
||||||
mbedtls_sha256_starts((mbedtls_sha256_context*)&o->state, 0);
|
mbedtls_sha256_starts((mbedtls_sha256_context *)&o->state, 0);
|
||||||
if (n_args == 1) {
|
if (n_args == 1) {
|
||||||
uhashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
uhashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
|
|||||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||||
mbedtls_sha256_update((mbedtls_sha256_context*)&self->state, bufinfo.buf, bufinfo.len);
|
mbedtls_sha256_update((mbedtls_sha256_context *)&self->state, bufinfo.buf, bufinfo.len);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,25 +69,25 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
|||||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
vstr_t vstr;
|
vstr_t vstr;
|
||||||
vstr_init_len(&vstr, 32);
|
vstr_init_len(&vstr, 32);
|
||||||
mbedtls_sha256_finish((mbedtls_sha256_context*)&self->state, (unsigned char *)vstr.buf);
|
mbedtls_sha256_finish((mbedtls_sha256_context *)&self->state, (unsigned char *)vstr.buf);
|
||||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static void check_not_unicode(const mp_obj_t arg) {
|
static void check_not_unicode(const mp_obj_t arg) {
|
||||||
#if MICROPY_CPYTHON_COMPAT
|
#if MICROPY_CPYTHON_COMPAT
|
||||||
if (MP_OBJ_IS_STR(arg)) {
|
if (MP_OBJ_IS_STR(arg)) {
|
||||||
mp_raise_TypeError(translate("a bytes-like object is required"));
|
mp_raise_TypeError(translate("a bytes-like object is required"));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||||
mp_arg_check_num(n_args, kw_args, 0, 1, false);
|
mp_arg_check_num(n_args, kw_args, 0, 1, false);
|
||||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
|
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
|
||||||
o->base.type = type;
|
o->base.type = type;
|
||||||
sha256_init((CRYAL_SHA256_CTX*)o->state);
|
sha256_init((CRYAL_SHA256_CTX *)o->state);
|
||||||
if (n_args == 1) {
|
if (n_args == 1) {
|
||||||
uhashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
uhashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
|
|||||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||||
sha256_update((CRYAL_SHA256_CTX*)self->state, bufinfo.buf, bufinfo.len);
|
sha256_update((CRYAL_SHA256_CTX *)self->state, bufinfo.buf, bufinfo.len);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
|||||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
vstr_t vstr;
|
vstr_t vstr;
|
||||||
vstr_init_len(&vstr, SHA256_BLOCK_SIZE);
|
vstr_init_len(&vstr, SHA256_BLOCK_SIZE);
|
||||||
sha256_final((CRYAL_SHA256_CTX*)self->state, (byte*)vstr.buf);
|
sha256_final((CRYAL_SHA256_CTX *)self->state, (byte *)vstr.buf);
|
||||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -126,7 +126,7 @@ STATIC const mp_obj_type_t uhashlib_sha256_type = {
|
|||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
.name = MP_QSTR_sha256,
|
.name = MP_QSTR_sha256,
|
||||||
.make_new = uhashlib_sha256_make_new,
|
.make_new = uhashlib_sha256_make_new,
|
||||||
.locals_dict = (void*)&uhashlib_sha256_locals_dict,
|
.locals_dict = (void *)&uhashlib_sha256_locals_dict,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ STATIC mp_obj_t uhashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||||||
mp_arg_check_num(n_args, kw_args, 0, 1, false);
|
mp_arg_check_num(n_args, kw_args, 0, 1, false);
|
||||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(SHA1_CTX));
|
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(SHA1_CTX));
|
||||||
o->base.type = type;
|
o->base.type = type;
|
||||||
SHA1_Init((SHA1_CTX*)o->state);
|
SHA1_Init((SHA1_CTX *)o->state);
|
||||||
if (n_args == 1) {
|
if (n_args == 1) {
|
||||||
uhashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
|
uhashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) {
|
|||||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||||
SHA1_Update((SHA1_CTX*)self->state, bufinfo.buf, bufinfo.len);
|
SHA1_Update((SHA1_CTX *)self->state, bufinfo.buf, bufinfo.len);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
|
|||||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
vstr_t vstr;
|
vstr_t vstr;
|
||||||
vstr_init_len(&vstr, SHA1_SIZE);
|
vstr_init_len(&vstr, SHA1_SIZE);
|
||||||
SHA1_Final((byte*)vstr.buf, (SHA1_CTX*)self->state);
|
SHA1_Final((byte *)vstr.buf, (SHA1_CTX *)self->state);
|
||||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -168,8 +168,8 @@ STATIC mp_obj_t uhashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context));
|
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context));
|
||||||
o->base.type = type;
|
o->base.type = type;
|
||||||
mbedtls_sha1_init((mbedtls_sha1_context*)o->state);
|
mbedtls_sha1_init((mbedtls_sha1_context *)o->state);
|
||||||
mbedtls_sha1_starts((mbedtls_sha1_context*)o->state);
|
mbedtls_sha1_starts((mbedtls_sha1_context *)o->state);
|
||||||
if (n_args == 1) {
|
if (n_args == 1) {
|
||||||
uhashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
|
uhashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) {
|
|||||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||||
mbedtls_sha1_update((mbedtls_sha1_context*)self->state, bufinfo.buf, bufinfo.len);
|
mbedtls_sha1_update((mbedtls_sha1_context *)self->state, bufinfo.buf, bufinfo.len);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,8 +188,8 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
|
|||||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
vstr_t vstr;
|
vstr_t vstr;
|
||||||
vstr_init_len(&vstr, 20);
|
vstr_init_len(&vstr, 20);
|
||||||
mbedtls_sha1_finish((mbedtls_sha1_context*)self->state, (byte*)vstr.buf);
|
mbedtls_sha1_finish((mbedtls_sha1_context *)self->state, (byte *)vstr.buf);
|
||||||
mbedtls_sha1_free((mbedtls_sha1_context*)self->state);
|
mbedtls_sha1_free((mbedtls_sha1_context *)self->state);
|
||||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -207,7 +207,7 @@ STATIC const mp_obj_type_t uhashlib_sha1_type = {
|
|||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
.name = MP_QSTR_sha1,
|
.name = MP_QSTR_sha1,
|
||||||
.make_new = uhashlib_sha1_make_new,
|
.make_new = uhashlib_sha1_make_new,
|
||||||
.locals_dict = (void*)&uhashlib_sha1_locals_dict,
|
.locals_dict = (void *)&uhashlib_sha1_locals_dict,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -225,11 +225,11 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uhashlib_globals, mp_module_uhashlib_globa
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_uhashlib = {
|
const mp_obj_module_t mp_module_uhashlib = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_uhashlib_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_uhashlib_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#if MICROPY_PY_UHASHLIB_SHA256
|
#if MICROPY_PY_UHASHLIB_SHA256
|
||||||
#include "crypto-algorithms/sha256.c"
|
#include "crypto-algorithms/sha256.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif //MICROPY_PY_UHASHLIB
|
#endif // MICROPY_PY_UHASHLIB
|
||||||
|
@ -95,7 +95,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uheapq_globals, mp_module_uheapq_globals_t
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_uheapq = {
|
const mp_obj_module_t mp_module_uheapq = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_uheapq_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_uheapq_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //MICROPY_PY_UHEAPQ
|
#endif // MICROPY_PY_UHEAPQ
|
||||||
|
@ -85,8 +85,8 @@ STATIC byte ujson_stream_next(ujson_stream_t *s) {
|
|||||||
#define CIRCUITPY_JSON_READ_CHUNK_SIZE 64
|
#define CIRCUITPY_JSON_READ_CHUNK_SIZE 64
|
||||||
|
|
||||||
STATIC mp_uint_t ujson_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) {
|
STATIC mp_uint_t ujson_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) {
|
||||||
(void) size; // Ignore size because we know it's always 1.
|
(void)size; // Ignore size because we know it's always 1.
|
||||||
ujson_stream_t* s = obj;
|
ujson_stream_t *s = obj;
|
||||||
|
|
||||||
if (s->start == s->end) {
|
if (s->start == s->end) {
|
||||||
*errcode = 0;
|
*errcode = 0;
|
||||||
@ -99,7 +99,7 @@ STATIC mp_uint_t ujson_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size,
|
|||||||
s->end = mp_obj_get_int(ret);
|
s->end = mp_obj_get_int(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
*((uint8_t *)buf) = ((uint8_t*) s->bytearray_obj.items)[s->start];
|
*((uint8_t *)buf) = ((uint8_t *)s->bytearray_obj.items)[s->start];
|
||||||
s->start++;
|
s->start++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ STATIC mp_obj_t _mod_ujson_load(mp_obj_t stream_obj, bool return_first_json) {
|
|||||||
mp_obj_t stack_key = MP_OBJ_NULL;
|
mp_obj_t stack_key = MP_OBJ_NULL;
|
||||||
S_NEXT(s);
|
S_NEXT(s);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
cont:
|
cont:
|
||||||
if (S_END(s)) {
|
if (S_END(s)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -186,11 +186,21 @@ STATIC mp_obj_t _mod_ujson_load(mp_obj_t stream_obj, bool return_first_json) {
|
|||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
c = S_NEXT(s);
|
c = S_NEXT(s);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'b': c = 0x08; break;
|
case 'b':
|
||||||
case 'f': c = 0x0c; break;
|
c = 0x08;
|
||||||
case 'n': c = 0x0a; break;
|
break;
|
||||||
case 'r': c = 0x0d; break;
|
case 'f':
|
||||||
case 't': c = 0x09; break;
|
c = 0x0c;
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
c = 0x0a;
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
c = 0x0d;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
c = 0x09;
|
||||||
|
break;
|
||||||
case 'u': {
|
case 'u': {
|
||||||
mp_uint_t num = 0;
|
mp_uint_t num = 0;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
@ -216,7 +226,16 @@ STATIC mp_obj_t _mod_ujson_load(mp_obj_t stream_obj, bool return_first_json) {
|
|||||||
next = mp_obj_new_str(vstr.buf, vstr.len);
|
next = mp_obj_new_str(vstr.buf, vstr.len);
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {
|
case '0':
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
case '8':
|
||||||
|
case '9': {
|
||||||
bool flt = false;
|
bool flt = false;
|
||||||
vstr_reset(&vstr);
|
vstr_reset(&vstr);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -298,7 +317,7 @@ STATIC mp_obj_t _mod_ujson_load(mp_obj_t stream_obj, bool return_first_json) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
success:
|
success:
|
||||||
// It is legal for a stream to have contents after JSON.
|
// It is legal for a stream to have contents after JSON.
|
||||||
// E.g., A UART is not closed after receiving an object; in load() we will
|
// E.g., A UART is not closed after receiving an object; in load() we will
|
||||||
// return the first complete JSON object, while in loads() we will retain
|
// return the first complete JSON object, while in loads() we will retain
|
||||||
@ -319,7 +338,7 @@ STATIC mp_obj_t _mod_ujson_load(mp_obj_t stream_obj, bool return_first_json) {
|
|||||||
vstr_clear(&vstr);
|
vstr_clear(&vstr);
|
||||||
return stack_top;
|
return stack_top;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
mp_raise_ValueError(translate("syntax error in JSON"));
|
mp_raise_ValueError(translate("syntax error in JSON"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,18 +350,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_load_obj, mod_ujson_load);
|
|||||||
STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
|
STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
|
||||||
size_t len;
|
size_t len;
|
||||||
const char *buf = mp_obj_str_get_data(obj, &len);
|
const char *buf = mp_obj_str_get_data(obj, &len);
|
||||||
vstr_t vstr = {len, len, (char*)buf, true};
|
vstr_t vstr = {len, len, (char *)buf, true};
|
||||||
mp_obj_stringio_t sio = {{&mp_type_stringio}, &vstr, 0, MP_OBJ_NULL};
|
mp_obj_stringio_t sio = {{&mp_type_stringio}, &vstr, 0, MP_OBJ_NULL};
|
||||||
return _mod_ujson_load(MP_OBJ_FROM_PTR(&sio), false);
|
return _mod_ujson_load(MP_OBJ_FROM_PTR(&sio), false);
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_loads_obj, mod_ujson_loads);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_loads_obj, mod_ujson_loads);
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t mp_module_ujson_globals_table[] = {
|
STATIC const mp_rom_map_elem_t mp_module_ujson_globals_table[] = {
|
||||||
#if CIRCUITPY
|
#if CIRCUITPY
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_json) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_json) },
|
||||||
#else
|
#else
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ujson) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ujson) },
|
||||||
#endif
|
#endif
|
||||||
{ MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_ujson_dump_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_ujson_dump_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_ujson_dumps_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_ujson_dumps_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_load), MP_ROM_PTR(&mod_ujson_load_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_load), MP_ROM_PTR(&mod_ujson_load_obj) },
|
||||||
@ -353,7 +372,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_ujson_globals, mp_module_ujson_globals_tab
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_ujson = {
|
const mp_obj_module_t mp_module_ujson = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_ujson_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_ujson_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //MICROPY_PY_UJSON
|
#endif // MICROPY_PY_UJSON
|
||||||
|
@ -18,15 +18,14 @@
|
|||||||
STATIC uint32_t yasmarang_pad = 0xeda4baba, yasmarang_n = 69, yasmarang_d = 233;
|
STATIC uint32_t yasmarang_pad = 0xeda4baba, yasmarang_n = 69, yasmarang_d = 233;
|
||||||
STATIC uint8_t yasmarang_dat = 0;
|
STATIC uint8_t yasmarang_dat = 0;
|
||||||
|
|
||||||
STATIC uint32_t yasmarang(void)
|
STATIC uint32_t yasmarang(void) {
|
||||||
{
|
yasmarang_pad += yasmarang_dat + yasmarang_d * yasmarang_n;
|
||||||
yasmarang_pad += yasmarang_dat + yasmarang_d * yasmarang_n;
|
yasmarang_pad = (yasmarang_pad << 3) + (yasmarang_pad >> 29);
|
||||||
yasmarang_pad = (yasmarang_pad<<3) + (yasmarang_pad>>29);
|
yasmarang_n = yasmarang_pad | 2;
|
||||||
yasmarang_n = yasmarang_pad | 2;
|
yasmarang_d ^= (yasmarang_pad << 31) + (yasmarang_pad >> 1);
|
||||||
yasmarang_d ^= (yasmarang_pad<<31) + (yasmarang_pad>>1);
|
yasmarang_dat ^= (char)yasmarang_pad ^ (yasmarang_d >> 8) ^ 1;
|
||||||
yasmarang_dat ^= (char) yasmarang_pad ^ (yasmarang_d>>8) ^ 1;
|
|
||||||
|
|
||||||
return (yasmarang_pad^(yasmarang_d<<5)^(yasmarang_pad>>18)^(yasmarang_dat<<1));
|
return yasmarang_pad ^ (yasmarang_d << 5) ^ (yasmarang_pad >> 18) ^ (yasmarang_dat << 1);
|
||||||
} /* yasmarang */
|
} /* yasmarang */
|
||||||
|
|
||||||
// End of Yasmarang
|
// End of Yasmarang
|
||||||
@ -148,9 +147,11 @@ STATIC mp_float_t yasmarang_float(void) {
|
|||||||
union {
|
union {
|
||||||
mp_float_t f;
|
mp_float_t f;
|
||||||
#if MP_ENDIANNESS_LITTLE
|
#if MP_ENDIANNESS_LITTLE
|
||||||
struct { mp_float_int_t frc:MP_FLOAT_FRAC_BITS, exp:MP_FLOAT_EXP_BITS, sgn:1; } p;
|
struct { mp_float_int_t frc : MP_FLOAT_FRAC_BITS, exp : MP_FLOAT_EXP_BITS, sgn : 1;
|
||||||
|
} p;
|
||||||
#else
|
#else
|
||||||
struct { mp_float_int_t sgn:1, exp:MP_FLOAT_EXP_BITS, frc:MP_FLOAT_FRAC_BITS; } p;
|
struct { mp_float_int_t sgn : 1, exp : MP_FLOAT_EXP_BITS, frc : MP_FLOAT_FRAC_BITS;
|
||||||
|
} p;
|
||||||
#endif
|
#endif
|
||||||
} u;
|
} u;
|
||||||
u.p.sgn = 0;
|
u.p.sgn = 0;
|
||||||
@ -198,7 +199,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_urandom_globals, mp_module_urandom_globals
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_urandom = {
|
const mp_obj_module_t mp_module_urandom = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_urandom_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_urandom_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //MICROPY_PY_URANDOM
|
#endif // MICROPY_PY_URANDOM
|
||||||
|
@ -52,7 +52,7 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
return mp_obj_new_str_of_type(mp_obj_get_type(self->str),
|
return mp_obj_new_str_of_type(mp_obj_get_type(self->str),
|
||||||
(const byte*)start, self->caps[no * 2 + 1] - start);
|
(const byte *)start, self->caps[no * 2 + 1] - start);
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_2(match_group_obj, match_group);
|
MP_DEFINE_CONST_FUN_OBJ_2(match_group_obj, match_group);
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ STATIC const mp_obj_type_t match_type = {
|
|||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
.name = MP_QSTR_match,
|
.name = MP_QSTR_match,
|
||||||
.print = match_print,
|
.print = match_print,
|
||||||
.locals_dict = (void*)&match_locals_dict,
|
.locals_dict = (void *)&match_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||||
@ -157,7 +157,7 @@ STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
|||||||
size_t len;
|
size_t len;
|
||||||
subj.begin = mp_obj_str_get_data(args[1], &len);
|
subj.begin = mp_obj_str_get_data(args[1], &len);
|
||||||
subj.end = subj.begin + len;
|
subj.end = subj.begin + len;
|
||||||
#if MICROPY_PY_URE_MATCH_SPAN_START_END
|
#if MICROPY_PY_URE_MATCH_SPAN_START_END
|
||||||
if (n_args > 2) {
|
if (n_args > 2) {
|
||||||
const mp_obj_type_t *self_type = mp_obj_get_type(args[1]);
|
const mp_obj_type_t *self_type = mp_obj_get_type(args[1]);
|
||||||
mp_int_t str_len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(args[1]));
|
mp_int_t str_len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(args[1]));
|
||||||
@ -185,14 +185,14 @@ STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
|||||||
subj.begin = (const char *)pos_ptr;
|
subj.begin = (const char *)pos_ptr;
|
||||||
subj.end = (const char *)endpos_ptr;
|
subj.end = (const char *)endpos_ptr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
int caps_num = (self->re.sub + 1) * 2;
|
int caps_num = (self->re.sub + 1) * 2;
|
||||||
mp_obj_match_t *match = m_new_obj_var(mp_obj_match_t, char*, caps_num);
|
mp_obj_match_t *match = m_new_obj_var(mp_obj_match_t, char *, caps_num);
|
||||||
// cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char
|
// cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char
|
||||||
memset((char*)match->caps, 0, caps_num * sizeof(char*));
|
memset((char *)match->caps, 0, caps_num * sizeof(char *));
|
||||||
int res = re1_5_recursiveloopprog(&self->re, &subj, match->caps, caps_num, is_anchored);
|
int res = re1_5_recursiveloopprog(&self->re, &subj, match->caps, caps_num, is_anchored);
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
m_del_var(mp_obj_match_t, char*, caps_num, match);
|
m_del_var(mp_obj_match_t, char *, caps_num, match);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,10 +227,10 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t retval = mp_obj_new_list(0, NULL);
|
mp_obj_t retval = mp_obj_new_list(0, NULL);
|
||||||
const char **caps = mp_local_alloc(caps_num * sizeof(char*));
|
const char **caps = mp_local_alloc(caps_num * sizeof(char *));
|
||||||
while (true) {
|
while (true) {
|
||||||
// cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char
|
// cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char
|
||||||
memset((char**)caps, 0, caps_num * sizeof(char*));
|
memset((char **)caps, 0, caps_num * sizeof(char *));
|
||||||
int res = re1_5_recursiveloopprog(&self->re, &subj, caps, caps_num, false);
|
int res = re1_5_recursiveloopprog(&self->re, &subj, caps, caps_num, false);
|
||||||
|
|
||||||
// if we didn't have a match, or had an empty match, it's time to stop
|
// if we didn't have a match, or had an empty match, it's time to stop
|
||||||
@ -238,7 +238,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte*)subj.begin, caps[0] - subj.begin);
|
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte *)subj.begin, caps[0] - subj.begin);
|
||||||
mp_obj_list_append(retval, s);
|
mp_obj_list_append(retval, s);
|
||||||
if (self->re.sub > 0) {
|
if (self->re.sub > 0) {
|
||||||
mp_raise_NotImplementedError(translate("Splitting with sub-captures"));
|
mp_raise_NotImplementedError(translate("Splitting with sub-captures"));
|
||||||
@ -249,9 +249,9 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cast is a workaround for a bug in msvc (see above)
|
// cast is a workaround for a bug in msvc (see above)
|
||||||
mp_local_free((char**)caps);
|
mp_local_free((char **)caps);
|
||||||
|
|
||||||
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte*)subj.begin, subj.end - subj.begin);
|
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte *)subj.begin, subj.end - subj.begin);
|
||||||
mp_obj_list_append(retval, s);
|
mp_obj_list_append(retval, s);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@ -278,14 +278,14 @@ STATIC mp_obj_t re_sub_helper(mp_obj_t self_in, size_t n_args, const mp_obj_t *a
|
|||||||
|
|
||||||
vstr_t vstr_return;
|
vstr_t vstr_return;
|
||||||
vstr_return.buf = NULL; // We'll init the vstr after the first match
|
vstr_return.buf = NULL; // We'll init the vstr after the first match
|
||||||
mp_obj_match_t *match = mp_local_alloc(sizeof(mp_obj_match_t) + caps_num * sizeof(char*));
|
mp_obj_match_t *match = mp_local_alloc(sizeof(mp_obj_match_t) + caps_num * sizeof(char *));
|
||||||
match->base.type = &match_type;
|
match->base.type = &match_type;
|
||||||
match->num_matches = caps_num / 2; // caps_num counts start and end pointers
|
match->num_matches = caps_num / 2; // caps_num counts start and end pointers
|
||||||
match->str = where;
|
match->str = where;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char
|
// cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char
|
||||||
memset((char*)match->caps, 0, caps_num * sizeof(char*));
|
memset((char *)match->caps, 0, caps_num * sizeof(char *));
|
||||||
int res = re1_5_recursiveloopprog(&self->re, &subj, match->caps, caps_num, false);
|
int res = re1_5_recursiveloopprog(&self->re, &subj, match->caps, caps_num, false);
|
||||||
|
|
||||||
// If we didn't have a match, or had an empty match, it's time to stop
|
// If we didn't have a match, or had an empty match, it's time to stop
|
||||||
@ -302,7 +302,7 @@ STATIC mp_obj_t re_sub_helper(mp_obj_t self_in, size_t n_args, const mp_obj_t *a
|
|||||||
vstr_add_strn(&vstr_return, subj.begin, match->caps[0] - subj.begin);
|
vstr_add_strn(&vstr_return, subj.begin, match->caps[0] - subj.begin);
|
||||||
|
|
||||||
// Get replacement string
|
// Get replacement string
|
||||||
const char* repl = mp_obj_str_get_str((mp_obj_is_callable(replace) ? mp_call_function_1(replace, MP_OBJ_FROM_PTR(match)) : replace));
|
const char *repl = mp_obj_str_get_str((mp_obj_is_callable(replace) ? mp_call_function_1(replace, MP_OBJ_FROM_PTR(match)) : replace));
|
||||||
|
|
||||||
// Append replacement string to result, substituting any regex groups
|
// Append replacement string to result, substituting any regex groups
|
||||||
while (*repl != '\0') {
|
while (*repl != '\0') {
|
||||||
@ -384,13 +384,13 @@ STATIC MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table);
|
|||||||
|
|
||||||
STATIC const mp_obj_type_t re_type = {
|
STATIC const mp_obj_type_t re_type = {
|
||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
#if CIRCUITPY
|
#if CIRCUITPY
|
||||||
.name = MP_QSTR_re,
|
.name = MP_QSTR_re,
|
||||||
#else
|
#else
|
||||||
.name = MP_QSTR_ure,
|
.name = MP_QSTR_ure,
|
||||||
#endif
|
#endif
|
||||||
.print = re_print,
|
.print = re_print,
|
||||||
.locals_dict = (void*)&re_locals_dict,
|
.locals_dict = (void *)&re_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
|
||||||
@ -407,7 +407,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
|
|||||||
}
|
}
|
||||||
int error = re1_5_compilecode(&o->re, re_str);
|
int error = re1_5_compilecode(&o->re, re_str);
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
error:
|
error:
|
||||||
mp_raise_ValueError(translate("Error in regex"));
|
mp_raise_ValueError(translate("Error in regex"));
|
||||||
}
|
}
|
||||||
if (flags & FLAG_DEBUG) {
|
if (flags & FLAG_DEBUG) {
|
||||||
@ -445,11 +445,11 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_re_sub_obj, 3, 5, mod_re_sub);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = {
|
STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = {
|
||||||
#if CIRCUITPY
|
#if CIRCUITPY
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_re) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_re) },
|
||||||
#else
|
#else
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ure) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ure) },
|
||||||
#endif
|
#endif
|
||||||
{ MP_ROM_QSTR(MP_QSTR_compile), MP_ROM_PTR(&mod_re_compile_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_compile), MP_ROM_PTR(&mod_re_compile_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_match), MP_ROM_PTR(&mod_re_match_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_match), MP_ROM_PTR(&mod_re_match_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_search), MP_ROM_PTR(&mod_re_search_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_search), MP_ROM_PTR(&mod_re_search_obj) },
|
||||||
@ -463,7 +463,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_re_globals, mp_module_re_globals_table);
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_ure = {
|
const mp_obj_module_t mp_module_ure = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_re_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_re_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Source files #include'd here to make sure they're compiled in
|
// Source files #include'd here to make sure they're compiled in
|
||||||
@ -475,4 +475,4 @@ const mp_obj_module_t mp_module_ure = {
|
|||||||
#include "re1.5/recursiveloop.c"
|
#include "re1.5/recursiveloop.c"
|
||||||
#include "re1.5/charclass.c"
|
#include "re1.5/charclass.c"
|
||||||
|
|
||||||
#endif //MICROPY_PY_URE
|
#endif // MICROPY_PY_URE
|
||||||
|
@ -45,9 +45,9 @@ STATIC void poll_map_add(mp_map_t *poll_map, const mp_obj_t *obj, mp_uint_t obj_
|
|||||||
} else {
|
} else {
|
||||||
// object exists; update its flags
|
// object exists; update its flags
|
||||||
if (or_flags) {
|
if (or_flags) {
|
||||||
((poll_obj_t*)elem->value)->flags |= flags;
|
((poll_obj_t *)elem->value)->flags |= flags;
|
||||||
} else {
|
} else {
|
||||||
((poll_obj_t*)elem->value)->flags = flags;
|
((poll_obj_t *)elem->value)->flags = flags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, mp_uint_t *rwx_num) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
poll_obj_t *poll_obj = (poll_obj_t*)poll_map->table[i].value;
|
poll_obj_t *poll_obj = (poll_obj_t *)poll_map->table[i].value;
|
||||||
int errcode;
|
int errcode;
|
||||||
mp_int_t ret = poll_obj->ioctl(poll_obj->obj, MP_STREAM_POLL, poll_obj->flags, &errcode);
|
mp_int_t ret = poll_obj->ioctl(poll_obj->obj, MP_STREAM_POLL, poll_obj->flags, &errcode);
|
||||||
poll_obj->flags_ret = ret;
|
poll_obj->flags_ret = ret;
|
||||||
@ -138,15 +138,15 @@ STATIC mp_obj_t select_select(uint n_args, const mp_obj_t *args) {
|
|||||||
if (!MP_MAP_SLOT_IS_FILLED(&poll_map, i)) {
|
if (!MP_MAP_SLOT_IS_FILLED(&poll_map, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
poll_obj_t *poll_obj = (poll_obj_t*)poll_map.table[i].value;
|
poll_obj_t *poll_obj = (poll_obj_t *)poll_map.table[i].value;
|
||||||
if (poll_obj->flags_ret & MP_STREAM_POLL_RD) {
|
if (poll_obj->flags_ret & MP_STREAM_POLL_RD) {
|
||||||
((mp_obj_list_t*)list_array[0])->items[rwx_len[0]++] = poll_obj->obj;
|
((mp_obj_list_t *)list_array[0])->items[rwx_len[0]++] = poll_obj->obj;
|
||||||
}
|
}
|
||||||
if (poll_obj->flags_ret & MP_STREAM_POLL_WR) {
|
if (poll_obj->flags_ret & MP_STREAM_POLL_WR) {
|
||||||
((mp_obj_list_t*)list_array[1])->items[rwx_len[1]++] = poll_obj->obj;
|
((mp_obj_list_t *)list_array[1])->items[rwx_len[1]++] = poll_obj->obj;
|
||||||
}
|
}
|
||||||
if ((poll_obj->flags_ret & ~(MP_STREAM_POLL_RD | MP_STREAM_POLL_WR)) != 0) {
|
if ((poll_obj->flags_ret & ~(MP_STREAM_POLL_RD | MP_STREAM_POLL_WR)) != 0) {
|
||||||
((mp_obj_list_t*)list_array[2])->items[rwx_len[2]++] = poll_obj->obj;
|
((mp_obj_list_t *)list_array[2])->items[rwx_len[2]++] = poll_obj->obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mp_map_deinit(&poll_map);
|
mp_map_deinit(&poll_map);
|
||||||
@ -199,7 +199,7 @@ STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmas
|
|||||||
if (elem == NULL) {
|
if (elem == NULL) {
|
||||||
mp_raise_OSError(MP_ENOENT);
|
mp_raise_OSError(MP_ENOENT);
|
||||||
}
|
}
|
||||||
((poll_obj_t*)elem->value)->flags = mp_obj_get_int(eventmask_in);
|
((poll_obj_t *)elem->value)->flags = mp_obj_get_int(eventmask_in);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_3(poll_modify_obj, poll_modify);
|
MP_DEFINE_CONST_FUN_OBJ_3(poll_modify_obj, poll_modify);
|
||||||
@ -249,7 +249,7 @@ STATIC mp_obj_t poll_poll(uint n_args, const mp_obj_t *args) {
|
|||||||
if (!MP_MAP_SLOT_IS_FILLED(&self->poll_map, i)) {
|
if (!MP_MAP_SLOT_IS_FILLED(&self->poll_map, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
poll_obj_t *poll_obj = (poll_obj_t*)self->poll_map.table[i].value;
|
poll_obj_t *poll_obj = (poll_obj_t *)self->poll_map.table[i].value;
|
||||||
if (poll_obj->flags_ret != 0) {
|
if (poll_obj->flags_ret != 0) {
|
||||||
mp_obj_t tuple[2] = {poll_obj->obj, MP_OBJ_NEW_SMALL_INT(poll_obj->flags_ret)};
|
mp_obj_t tuple[2] = {poll_obj->obj, MP_OBJ_NEW_SMALL_INT(poll_obj->flags_ret)};
|
||||||
ret_list->items[n_ready++] = mp_obj_new_tuple(2, tuple);
|
ret_list->items[n_ready++] = mp_obj_new_tuple(2, tuple);
|
||||||
@ -292,7 +292,7 @@ STATIC mp_obj_t poll_iternext(mp_obj_t self_in) {
|
|||||||
if (!MP_MAP_SLOT_IS_FILLED(&self->poll_map, i)) {
|
if (!MP_MAP_SLOT_IS_FILLED(&self->poll_map, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
poll_obj_t *poll_obj = (poll_obj_t*)self->poll_map.table[i].value;
|
poll_obj_t *poll_obj = (poll_obj_t *)self->poll_map.table[i].value;
|
||||||
if (poll_obj->flags_ret != 0) {
|
if (poll_obj->flags_ret != 0) {
|
||||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->ret_tuple);
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->ret_tuple);
|
||||||
t->items[0] = poll_obj->obj;
|
t->items[0] = poll_obj->obj;
|
||||||
@ -324,7 +324,7 @@ STATIC const mp_obj_type_t mp_type_poll = {
|
|||||||
.name = MP_QSTR_poll,
|
.name = MP_QSTR_poll,
|
||||||
.getiter = mp_identity_getiter,
|
.getiter = mp_identity_getiter,
|
||||||
.iternext = poll_iternext,
|
.iternext = poll_iternext,
|
||||||
.locals_dict = (void*)&poll_locals_dict,
|
.locals_dict = (void *)&poll_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \function poll()
|
/// \function poll()
|
||||||
@ -352,7 +352,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_t
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_uselect = {
|
const mp_obj_module_t mp_module_uselect = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_select_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_select_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_USELECT
|
#endif // MICROPY_PY_USELECT
|
||||||
|
@ -34,11 +34,11 @@ struct ssl_args {
|
|||||||
STATIC const mp_obj_type_t ussl_socket_type;
|
STATIC const mp_obj_type_t ussl_socket_type;
|
||||||
|
|
||||||
STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||||
#if MICROPY_PY_USSL_FINALISER
|
#if MICROPY_PY_USSL_FINALISER
|
||||||
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
||||||
#else
|
#else
|
||||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||||
#endif
|
#endif
|
||||||
o->base.type = &ussl_socket_type;
|
o->base.type = &ussl_socket_type;
|
||||||
o->buf = NULL;
|
o->buf = NULL;
|
||||||
o->bytes_left = 0;
|
o->bytes_left = 0;
|
||||||
@ -54,13 +54,13 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
|||||||
|
|
||||||
if (args->key.u_obj != mp_const_none) {
|
if (args->key.u_obj != mp_const_none) {
|
||||||
size_t len;
|
size_t len;
|
||||||
const byte *data = (const byte*)mp_obj_str_get_data(args->key.u_obj, &len);
|
const byte *data = (const byte *)mp_obj_str_get_data(args->key.u_obj, &len);
|
||||||
int res = ssl_obj_memory_load(o->ssl_ctx, SSL_OBJ_RSA_KEY, data, len, NULL);
|
int res = ssl_obj_memory_load(o->ssl_ctx, SSL_OBJ_RSA_KEY, data, len, NULL);
|
||||||
if (res != SSL_OK) {
|
if (res != SSL_OK) {
|
||||||
mp_raise_ValueError(translate("invalid key"));
|
mp_raise_ValueError(translate("invalid key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
data = (const byte*)mp_obj_str_get_data(args->cert.u_obj, &len);
|
data = (const byte *)mp_obj_str_get_data(args->cert.u_obj, &len);
|
||||||
res = ssl_obj_memory_load(o->ssl_ctx, SSL_OBJ_X509_CERT, data, len, NULL);
|
res = ssl_obj_memory_load(o->ssl_ctx, SSL_OBJ_X509_CERT, data, len, NULL);
|
||||||
if (res != SSL_OK) {
|
if (res != SSL_OK) {
|
||||||
mp_raise_ValueError(translate("invalid cert"));
|
mp_raise_ValueError(translate("invalid cert"));
|
||||||
@ -73,7 +73,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
|||||||
SSL_EXTENSIONS *ext = ssl_ext_new();
|
SSL_EXTENSIONS *ext = ssl_ext_new();
|
||||||
|
|
||||||
if (args->server_hostname.u_obj != mp_const_none) {
|
if (args->server_hostname.u_obj != mp_const_none) {
|
||||||
ext->host_name = (char*)mp_obj_str_get_str(args->server_hostname.u_obj);
|
ext->host_name = (char *)mp_obj_str_get_str(args->server_hostname.u_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
o->ssl_sock = ssl_client_new(o->ssl_ctx, (long)sock, NULL, 0, ext);
|
o->ssl_sock = ssl_client_new(o->ssl_ctx, (long)sock, NULL, 0, ext);
|
||||||
@ -192,9 +192,9 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||||
#if MICROPY_PY_USSL_FINALISER
|
#if MICROPY_PY_USSL_FINALISER
|
||||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table);
|
STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table);
|
||||||
@ -214,7 +214,7 @@ STATIC const mp_obj_type_t ussl_socket_type = {
|
|||||||
.getiter = NULL,
|
.getiter = NULL,
|
||||||
.iternext = NULL,
|
.iternext = NULL,
|
||||||
.protocol = &ussl_socket_stream_p,
|
.protocol = &ussl_socket_stream_p,
|
||||||
.locals_dict = (void*)&ussl_socket_locals_dict,
|
.locals_dict = (void *)&ussl_socket_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
@ -231,7 +231,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_
|
|||||||
|
|
||||||
struct ssl_args args;
|
struct ssl_args args;
|
||||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
|
||||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args);
|
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&args);
|
||||||
|
|
||||||
return MP_OBJ_FROM_PTR(socket_new(sock, &args));
|
return MP_OBJ_FROM_PTR(socket_new(sock, &args));
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table);
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_ussl = {
|
const mp_obj_module_t mp_module_ussl = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_ssl_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_ssl_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_USSL
|
#endif // MICROPY_PY_USSL
|
||||||
|
@ -53,7 +53,7 @@ STATIC void mbedtls_debug(void *ctx, int level, const char *file, int line, cons
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
|
STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
|
||||||
mp_obj_t sock = *(mp_obj_t*)ctx;
|
mp_obj_t sock = *(mp_obj_t *)ctx;
|
||||||
|
|
||||||
const mp_stream_p_t *sock_stream = mp_get_stream(sock);
|
const mp_stream_p_t *sock_stream = mp_get_stream(sock);
|
||||||
int err;
|
int err;
|
||||||
@ -70,7 +70,7 @@ STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
|
STATIC int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
|
||||||
mp_obj_t sock = *(mp_obj_t*)ctx;
|
mp_obj_t sock = *(mp_obj_t *)ctx;
|
||||||
|
|
||||||
const mp_stream_p_t *sock_stream = mp_get_stream(sock);
|
const mp_stream_p_t *sock_stream = mp_get_stream(sock);
|
||||||
int err;
|
int err;
|
||||||
@ -91,11 +91,11 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
|||||||
// Verify the socket object has the full stream protocol
|
// Verify the socket object has the full stream protocol
|
||||||
mp_get_stream_raise(sock, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
|
mp_get_stream_raise(sock, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
|
||||||
|
|
||||||
#if MICROPY_PY_USSL_FINALISER
|
#if MICROPY_PY_USSL_FINALISER
|
||||||
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
||||||
#else
|
#else
|
||||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||||
#endif
|
#endif
|
||||||
o->base.type = &ussl_socket_type;
|
o->base.type = &ussl_socket_type;
|
||||||
o->sock = sock;
|
o->sock = sock;
|
||||||
|
|
||||||
@ -119,9 +119,9 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = mbedtls_ssl_config_defaults(&o->conf,
|
ret = mbedtls_ssl_config_defaults(&o->conf,
|
||||||
args->server_side.u_bool ? MBEDTLS_SSL_IS_SERVER : MBEDTLS_SSL_IS_CLIENT,
|
args->server_side.u_bool ? MBEDTLS_SSL_IS_SERVER : MBEDTLS_SSL_IS_CLIENT,
|
||||||
MBEDTLS_SSL_TRANSPORT_STREAM,
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
||||||
MBEDTLS_SSL_PRESET_DEFAULT);
|
MBEDTLS_SSL_PRESET_DEFAULT);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -149,13 +149,13 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
|||||||
|
|
||||||
if (args->key.u_obj != MP_OBJ_NULL) {
|
if (args->key.u_obj != MP_OBJ_NULL) {
|
||||||
size_t key_len;
|
size_t key_len;
|
||||||
const byte *key = (const byte*)mp_obj_str_get_data(args->key.u_obj, &key_len);
|
const byte *key = (const byte *)mp_obj_str_get_data(args->key.u_obj, &key_len);
|
||||||
// len should include terminating null
|
// len should include terminating null
|
||||||
ret = mbedtls_pk_parse_key(&o->pkey, key, key_len + 1, NULL, 0);
|
ret = mbedtls_pk_parse_key(&o->pkey, key, key_len + 1, NULL, 0);
|
||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
|
|
||||||
size_t cert_len;
|
size_t cert_len;
|
||||||
const byte *cert = (const byte*)mp_obj_str_get_data(args->cert.u_obj, &cert_len);
|
const byte *cert = (const byte *)mp_obj_str_get_data(args->cert.u_obj, &cert_len);
|
||||||
// len should include terminating null
|
// len should include terminating null
|
||||||
ret = mbedtls_x509_crt_parse(&o->cert, cert, cert_len + 1);
|
ret = mbedtls_x509_crt_parse(&o->cert, cert, cert_len + 1);
|
||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
@ -194,7 +194,7 @@ STATIC mp_obj_t mod_ssl_getpeercert(mp_obj_t o_in, mp_obj_t binary_form) {
|
|||||||
if (!mp_obj_is_true(binary_form)) {
|
if (!mp_obj_is_true(binary_form)) {
|
||||||
mp_raise_NotImplementedError(NULL);
|
mp_raise_NotImplementedError(NULL);
|
||||||
}
|
}
|
||||||
const mbedtls_x509_crt* peer_cert = mbedtls_ssl_get_peer_cert(&o->ssl);
|
const mbedtls_x509_crt *peer_cert = mbedtls_ssl_get_peer_cert(&o->ssl);
|
||||||
return mp_obj_new_bytes(peer_cert->raw.p, peer_cert->raw.len);
|
return mp_obj_new_bytes(peer_cert->raw.p, peer_cert->raw.len);
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_ssl_getpeercert_obj, mod_ssl_getpeercert);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_ssl_getpeercert_obj, mod_ssl_getpeercert);
|
||||||
@ -275,9 +275,9 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||||
#if MICROPY_PY_USSL_FINALISER
|
#if MICROPY_PY_USSL_FINALISER
|
||||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||||
#endif
|
#endif
|
||||||
{ MP_ROM_QSTR(MP_QSTR_getpeercert), MP_ROM_PTR(&mod_ssl_getpeercert_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_getpeercert), MP_ROM_PTR(&mod_ssl_getpeercert_obj) },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ STATIC const mp_obj_type_t ussl_socket_type = {
|
|||||||
.getiter = NULL,
|
.getiter = NULL,
|
||||||
.iternext = NULL,
|
.iternext = NULL,
|
||||||
.protocol = &ussl_socket_stream_p,
|
.protocol = &ussl_socket_stream_p,
|
||||||
.locals_dict = (void*)&ussl_socket_locals_dict,
|
.locals_dict = (void *)&ussl_socket_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
@ -315,7 +315,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_
|
|||||||
|
|
||||||
struct ssl_args args;
|
struct ssl_args args;
|
||||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
|
||||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args);
|
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&args);
|
||||||
|
|
||||||
return MP_OBJ_FROM_PTR(socket_new(sock, &args));
|
return MP_OBJ_FROM_PTR(socket_new(sock, &args));
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table);
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_ussl = {
|
const mp_obj_module_t mp_module_ussl = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_ssl_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_ssl_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_USSL
|
#endif // MICROPY_PY_USSL
|
||||||
|
@ -171,9 +171,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_utimeq_dump_obj, mod_utimeq_dump);
|
|||||||
STATIC mp_obj_t utimeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
STATIC mp_obj_t utimeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||||
mp_obj_utimeq_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_utimeq_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);
|
case MP_UNARY_OP_BOOL:
|
||||||
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
|
return mp_obj_new_bool(self->len != 0);
|
||||||
default: return MP_OBJ_NULL; // op not supported
|
case MP_UNARY_OP_LEN:
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(self->len);
|
||||||
|
default:
|
||||||
|
return MP_OBJ_NULL; // op not supported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +196,7 @@ STATIC const mp_obj_type_t utimeq_type = {
|
|||||||
.name = MP_QSTR_utimeq,
|
.name = MP_QSTR_utimeq,
|
||||||
.make_new = utimeq_make_new,
|
.make_new = utimeq_make_new,
|
||||||
.unary_op = utimeq_unary_op,
|
.unary_op = utimeq_unary_op,
|
||||||
.locals_dict = (void*)&utimeq_locals_dict,
|
.locals_dict = (void *)&utimeq_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t mp_module_utimeq_globals_table[] = {
|
STATIC const mp_rom_map_elem_t mp_module_utimeq_globals_table[] = {
|
||||||
@ -205,7 +208,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_utimeq_globals, mp_module_utimeq_globals_t
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_utimeq = {
|
const mp_obj_module_t mp_module_utimeq = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_utimeq_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_utimeq_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //MICROPY_PY_UTIMEQ
|
#endif // MICROPY_PY_UTIMEQ
|
||||||
|
@ -31,9 +31,9 @@ typedef struct _mp_obj_decompio_t {
|
|||||||
} mp_obj_decompio_t;
|
} mp_obj_decompio_t;
|
||||||
|
|
||||||
STATIC int read_src_stream(TINF_DATA *data) {
|
STATIC int read_src_stream(TINF_DATA *data) {
|
||||||
byte *p = (void*)data;
|
byte *p = (void *)data;
|
||||||
p -= offsetof(mp_obj_decompio_t, decomp);
|
p -= offsetof(mp_obj_decompio_t, decomp);
|
||||||
mp_obj_decompio_t *self = (mp_obj_decompio_t*)p;
|
mp_obj_decompio_t *self = (mp_obj_decompio_t *)p;
|
||||||
|
|
||||||
const mp_stream_p_t *stream = mp_get_stream(self->src_stream);
|
const mp_stream_p_t *stream = mp_get_stream(self->src_stream);
|
||||||
int err;
|
int err;
|
||||||
@ -73,7 +73,7 @@ STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, cons
|
|||||||
} else if (dict_opt >= 0) {
|
} else if (dict_opt >= 0) {
|
||||||
dict_opt = uzlib_zlib_parse_header(&o->decomp);
|
dict_opt = uzlib_zlib_parse_header(&o->decomp);
|
||||||
if (dict_opt < 0) {
|
if (dict_opt < 0) {
|
||||||
header_error:
|
header_error:
|
||||||
mp_raise_ValueError(translate("compression header"));
|
mp_raise_ValueError(translate("compression header"));
|
||||||
}
|
}
|
||||||
dict_sz = 1 << dict_opt;
|
dict_sz = 1 << dict_opt;
|
||||||
@ -92,7 +92,7 @@ STATIC mp_uint_t decompio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er
|
|||||||
}
|
}
|
||||||
|
|
||||||
o->decomp.dest = buf;
|
o->decomp.dest = buf;
|
||||||
o->decomp.dest_limit = (unsigned char*)buf+size;
|
o->decomp.dest_limit = (unsigned char *)buf + size;
|
||||||
int st = uzlib_uncompress_chksum(&o->decomp);
|
int st = uzlib_uncompress_chksum(&o->decomp);
|
||||||
if (st == TINF_DONE) {
|
if (st == TINF_DONE) {
|
||||||
o->eof = true;
|
o->eof = true;
|
||||||
@ -101,7 +101,7 @@ STATIC mp_uint_t decompio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er
|
|||||||
*errcode = MP_EINVAL;
|
*errcode = MP_EINVAL;
|
||||||
return MP_STREAM_ERROR;
|
return MP_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
return o->decomp.dest - (byte*)buf;
|
return o->decomp.dest - (byte *)buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t decompio_locals_dict_table[] = {
|
STATIC const mp_rom_map_elem_t decompio_locals_dict_table[] = {
|
||||||
@ -122,7 +122,7 @@ STATIC const mp_obj_type_t decompio_type = {
|
|||||||
.name = MP_QSTR_DecompIO,
|
.name = MP_QSTR_DecompIO,
|
||||||
.make_new = decompio_make_new,
|
.make_new = decompio_make_new,
|
||||||
.protocol = &decompio_stream_p,
|
.protocol = &decompio_stream_p,
|
||||||
.locals_dict = (void*)&decompio_locals_dict,
|
.locals_dict = (void *)&decompio_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||||
@ -138,7 +138,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
|||||||
byte *dest_buf = m_new(byte, dest_buf_size);
|
byte *dest_buf = m_new(byte, dest_buf_size);
|
||||||
|
|
||||||
decomp->dest = dest_buf;
|
decomp->dest = dest_buf;
|
||||||
decomp->dest_limit = dest_buf+dest_buf_size;
|
decomp->dest_limit = dest_buf + dest_buf_size;
|
||||||
DEBUG_printf("uzlib: Initial out buffer: " UINT_FMT " bytes\n", decomp->destSize);
|
DEBUG_printf("uzlib: Initial out buffer: " UINT_FMT " bytes\n", decomp->destSize);
|
||||||
decomp->source = bufinfo.buf;
|
decomp->source = bufinfo.buf;
|
||||||
decomp->source_limit = (unsigned char *)bufinfo.buf + bufinfo.len;
|
decomp->source_limit = (unsigned char *)bufinfo.buf + bufinfo.len;
|
||||||
@ -173,7 +173,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
|||||||
|
|
||||||
mp_uint_t final_sz = decomp->dest - dest_buf;
|
mp_uint_t final_sz = decomp->dest - dest_buf;
|
||||||
DEBUG_printf("uzlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz);
|
DEBUG_printf("uzlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz);
|
||||||
dest_buf = (byte*)m_renew(byte, dest_buf, dest_buf_size, final_sz);
|
dest_buf = (byte *)m_renew(byte, dest_buf, dest_buf_size, final_sz);
|
||||||
mp_obj_t res = mp_obj_new_bytearray_by_ref(final_sz, dest_buf);
|
mp_obj_t res = mp_obj_new_bytearray_by_ref(final_sz, dest_buf);
|
||||||
m_del_obj(TINF_DATA, decomp);
|
m_del_obj(TINF_DATA, decomp);
|
||||||
return res;
|
return res;
|
||||||
@ -193,7 +193,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uzlib_globals, mp_module_uzlib_globals_tab
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_uzlib = {
|
const mp_obj_module_t mp_module_uzlib = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_uzlib_globals,
|
.globals = (mp_obj_dict_t *)&mp_module_uzlib_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Source files #include'd here to make sure they're compiled in
|
// Source files #include'd here to make sure they're compiled in
|
||||||
|
@ -127,7 +127,7 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {
|
|||||||
open_args[1] = MP_OBJ_NEW_QSTR(MP_QSTR_wb);
|
open_args[1] = MP_OBJ_NEW_QSTR(MP_QSTR_wb);
|
||||||
}
|
}
|
||||||
|
|
||||||
self->cur_file = mp_builtin_open(2, open_args, (mp_map_t*)&mp_const_empty_map);
|
self->cur_file = mp_builtin_open(2, open_args, (mp_map_t *)&mp_const_empty_map);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
struct mp_stream_seek_t seek = { .offset = self->hdr.offset, .whence = 0 };
|
struct mp_stream_seek_t seek = { .offset = self->hdr.offset, .whence = 0 };
|
||||||
@ -161,13 +161,13 @@ STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
|
|||||||
mp_obj_webrepl_t *self = self_in;
|
mp_obj_webrepl_t *self = self_in;
|
||||||
const mp_stream_p_t *sock_stream = mp_get_stream(self->sock);
|
const mp_stream_p_t *sock_stream = mp_get_stream(self->sock);
|
||||||
mp_uint_t out_sz = sock_stream->read(self->sock, buf, size, errcode);
|
mp_uint_t out_sz = sock_stream->read(self->sock, buf, size, errcode);
|
||||||
//DEBUG_printf("webrepl: Read %d initial bytes from websocket\n", out_sz);
|
// DEBUG_printf("webrepl: Read %d initial bytes from websocket\n", out_sz);
|
||||||
if (out_sz == 0 || out_sz == MP_STREAM_ERROR) {
|
if (out_sz == 0 || out_sz == MP_STREAM_ERROR) {
|
||||||
return out_sz;
|
return out_sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->state == STATE_PASSWD) {
|
if (self->state == STATE_PASSWD) {
|
||||||
char c = *(char*)buf;
|
char c = *(char *)buf;
|
||||||
if (c == '\r' || c == '\n') {
|
if (c == '\r' || c == '\n') {
|
||||||
self->hdr.fname[self->data_to_recv] = 0;
|
self->hdr.fname[self->data_to_recv] = 0;
|
||||||
DEBUG_printf("webrepl: entered password: %s\n", self->hdr.fname);
|
DEBUG_printf("webrepl: entered password: %s\n", self->hdr.fname);
|
||||||
@ -195,8 +195,8 @@ STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
|
|||||||
DEBUG_printf("webrepl: received bin data, hdr_to_recv: %d, data_to_recv=%d\n", self->hdr_to_recv, self->data_to_recv);
|
DEBUG_printf("webrepl: received bin data, hdr_to_recv: %d, data_to_recv=%d\n", self->hdr_to_recv, self->data_to_recv);
|
||||||
|
|
||||||
if (self->hdr_to_recv != 0) {
|
if (self->hdr_to_recv != 0) {
|
||||||
char *p = (char*)&self->hdr + sizeof(self->hdr) - self->hdr_to_recv;
|
char *p = (char *)&self->hdr + sizeof(self->hdr) - self->hdr_to_recv;
|
||||||
*p++ = *(char*)buf;
|
*p++ = *(char *)buf;
|
||||||
if (--self->hdr_to_recv != 0) {
|
if (--self->hdr_to_recv != 0) {
|
||||||
mp_uint_t hdr_sz = sock_stream->read(self->sock, p, self->hdr_to_recv, errcode);
|
mp_uint_t hdr_sz = sock_stream->read(self->sock, p, self->hdr_to_recv, errcode);
|
||||||
if (hdr_sz == MP_STREAM_ERROR) {
|
if (hdr_sz == MP_STREAM_ERROR) {
|
||||||
@ -217,7 +217,7 @@ STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
|
|||||||
|
|
||||||
if (self->data_to_recv != 0) {
|
if (self->data_to_recv != 0) {
|
||||||
static byte filebuf[512];
|
static byte filebuf[512];
|
||||||
filebuf[0] = *(byte*)buf;
|
filebuf[0] = *(byte *)buf;
|
||||||
mp_uint_t buf_sz = 1;
|
mp_uint_t buf_sz = 1;
|
||||||
if (--self->data_to_recv != 0) {
|
if (--self->data_to_recv != 0) {
|
||||||
size_t to_read = MIN(sizeof(filebuf) - 1, self->data_to_recv);
|
size_t to_read = MIN(sizeof(filebuf) - 1, self->data_to_recv);
|
||||||
@ -321,7 +321,7 @@ STATIC const mp_obj_type_t webrepl_type = {
|
|||||||
.name = MP_QSTR__webrepl,
|
.name = MP_QSTR__webrepl,
|
||||||
.make_new = webrepl_make_new,
|
.make_new = webrepl_make_new,
|
||||||
.protocol = &webrepl_stream_p,
|
.protocol = &webrepl_stream_p,
|
||||||
.locals_dict = (mp_obj_dict_t*)&webrepl_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&webrepl_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t webrepl_module_globals_table[] = {
|
STATIC const mp_rom_map_elem_t webrepl_module_globals_table[] = {
|
||||||
@ -334,7 +334,7 @@ STATIC MP_DEFINE_CONST_DICT(webrepl_module_globals, webrepl_module_globals_table
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_webrepl = {
|
const mp_obj_module_t mp_module_webrepl = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&webrepl_module_globals,
|
.globals = (mp_obj_dict_t *)&webrepl_module_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_WEBREPL
|
#endif // MICROPY_PY_WEBREPL
|
||||||
|
@ -50,11 +50,11 @@ STATIC mp_obj_t websocket_make_new(const mp_obj_type_t *type, size_t n_args, con
|
|||||||
if (n_args > 1 && args[1] == mp_const_true) {
|
if (n_args > 1 && args[1] == mp_const_true) {
|
||||||
o->opts |= BLOCKING_WRITE;
|
o->opts |= BLOCKING_WRITE;
|
||||||
}
|
}
|
||||||
return MP_OBJ_FROM_PTR(o);
|
return MP_OBJ_FROM_PTR(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
||||||
mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
const mp_stream_p_t *stream_p = mp_get_stream(self->sock);
|
const mp_stream_p_t *stream_p = mp_get_stream(self->sock);
|
||||||
while (1) {
|
while (1) {
|
||||||
if (self->to_recv != 0) {
|
if (self->to_recv != 0) {
|
||||||
@ -162,7 +162,7 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
|
|||||||
self->msg_sz -= out_sz;
|
self->msg_sz -= out_sz;
|
||||||
if (self->msg_sz == 0) {
|
if (self->msg_sz == 0) {
|
||||||
byte last_state;
|
byte last_state;
|
||||||
no_payload:
|
no_payload:
|
||||||
last_state = self->state;
|
last_state = self->state;
|
||||||
self->state = FRAME_HEADER;
|
self->state = FRAME_HEADER;
|
||||||
self->to_recv = 2;
|
self->to_recv = 2;
|
||||||
@ -179,7 +179,7 @@ no_payload:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//DEBUG_printf("Finished receiving ctrl message %x, ignoring\n", self->last_flags);
|
// DEBUG_printf("Finished receiving ctrl message %x, ignoring\n", self->last_flags);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ no_payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
|
STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||||
mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
assert(size < 0x10000);
|
assert(size < 0x10000);
|
||||||
byte header[4] = {0x80 | (self->opts & FRAME_OPCODE_MASK)};
|
byte header[4] = {0x80 | (self->opts & FRAME_OPCODE_MASK)};
|
||||||
int hdr_sz;
|
int hdr_sz;
|
||||||
@ -276,7 +276,7 @@ STATIC const mp_obj_type_t websocket_type = {
|
|||||||
.name = MP_QSTR_websocket,
|
.name = MP_QSTR_websocket,
|
||||||
.make_new = websocket_make_new,
|
.make_new = websocket_make_new,
|
||||||
.protocol = &websocket_stream_p,
|
.protocol = &websocket_stream_p,
|
||||||
.locals_dict = (void*)&websocket_locals_dict,
|
.locals_dict = (void *)&websocket_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t websocket_module_globals_table[] = {
|
STATIC const mp_rom_map_elem_t websocket_module_globals_table[] = {
|
||||||
@ -288,7 +288,7 @@ STATIC MP_DEFINE_CONST_DICT(websocket_module_globals, websocket_module_globals_t
|
|||||||
|
|
||||||
const mp_obj_module_t mp_module_websocket = {
|
const mp_obj_module_t mp_module_websocket = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&websocket_module_globals,
|
.globals = (mp_obj_dict_t *)&websocket_module_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_WEBSOCKET
|
#endif // MICROPY_PY_WEBSOCKET
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 2ecad9586d088ee66f1b208ff2204906eba9e987
|
Subproject commit b64fa6d4c73287edef9ccf09cfd6ec5009f9628b
|
@ -65,7 +65,7 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) {
|
|||||||
// Optimized formula avoiding if conditions. We adjust difference "forward",
|
// Optimized formula avoiding if conditions. We adjust difference "forward",
|
||||||
// wrap it around and adjust back.
|
// wrap it around and adjust back.
|
||||||
mp_int_t diff = ((end - start + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1))
|
mp_int_t diff = ((end - start + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1))
|
||||||
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
|
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
|
||||||
return MP_OBJ_NEW_SMALL_INT(diff);
|
return MP_OBJ_NEW_SMALL_INT(diff);
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj, time_ticks_diff);
|
MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj, time_ticks_diff);
|
||||||
|
10
extmod/vfs.c
10
extmod/vfs.c
@ -75,7 +75,7 @@ STATIC mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) {
|
|||||||
mp_vfs_mount_t *vfs = mp_vfs_lookup_path(path, &p_out);
|
mp_vfs_mount_t *vfs = mp_vfs_lookup_path(path, &p_out);
|
||||||
if (vfs != MP_VFS_NONE && vfs != MP_VFS_ROOT) {
|
if (vfs != MP_VFS_NONE && vfs != MP_VFS_ROOT) {
|
||||||
*path_out = mp_obj_new_str_of_type(mp_obj_get_type(path_in),
|
*path_out = mp_obj_new_str_of_type(mp_obj_get_type(path_in),
|
||||||
(const byte*)p_out, strlen(p_out));
|
(const byte *)p_out, strlen(p_out));
|
||||||
}
|
}
|
||||||
return vfs;
|
return vfs;
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the mounted object has the VFS protocol, call its import_stat helper
|
// If the mounted object has the VFS protocol, call its import_stat helper
|
||||||
const mp_vfs_proto_t *proto = (mp_vfs_proto_t*)mp_proto_get(MP_QSTR_protocol_vfs, vfs->obj);
|
const mp_vfs_proto_t *proto = (mp_vfs_proto_t *)mp_proto_get(MP_QSTR_protocol_vfs, vfs->obj);
|
||||||
if (proto != NULL) {
|
if (proto != NULL) {
|
||||||
return proto->import_stat(MP_OBJ_TO_PTR(vfs->obj), path_out);
|
return proto->import_stat(MP_OBJ_TO_PTR(vfs->obj), path_out);
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ mp_obj_t mp_vfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args
|
|||||||
vfs->next = NULL;
|
vfs->next = NULL;
|
||||||
|
|
||||||
// call the underlying object to do any mounting operation
|
// call the underlying object to do any mounting operation
|
||||||
mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t*)&args);
|
mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t *)&args);
|
||||||
|
|
||||||
// check that the destination mount point is unused
|
// check that the destination mount point is unused
|
||||||
const char *path_out;
|
const char *path_out;
|
||||||
@ -245,7 +245,7 @@ mp_obj_t mp_vfs_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
|||||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||||
|
|
||||||
mp_vfs_mount_t *vfs = lookup_path(args[ARG_file].u_obj, &args[ARG_file].u_obj);
|
mp_vfs_mount_t *vfs = lookup_path(args[ARG_file].u_obj, &args[ARG_file].u_obj);
|
||||||
return mp_vfs_proxy_call(vfs, MP_QSTR_open, 2, (mp_obj_t*)&args);
|
return mp_vfs_proxy_call(vfs, MP_QSTR_open, 2, (mp_obj_t *)&args);
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_vfs_open_obj, 0, mp_vfs_open);
|
MP_DEFINE_CONST_FUN_OBJ_KW(mp_vfs_open_obj, 0, mp_vfs_open);
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ mp_obj_t mp_vfs_ilistdir_it_iternext(mp_obj_t self_in) {
|
|||||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
||||||
t->items[0] = mp_obj_new_str_of_type(
|
t->items[0] = mp_obj_new_str_of_type(
|
||||||
self->is_str ? &mp_type_str : &mp_type_bytes,
|
self->is_str ? &mp_type_str : &mp_type_bytes,
|
||||||
(const byte*)vfs->str + 1, vfs->len - 1);
|
(const byte *)vfs->str + 1, vfs->len - 1);
|
||||||
t->items[1] = MP_OBJ_NEW_SMALL_INT(MP_S_IFDIR);
|
t->items[1] = MP_OBJ_NEW_SMALL_INT(MP_S_IFDIR);
|
||||||
t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // no inode number
|
t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // no inode number
|
||||||
return MP_OBJ_FROM_PTR(t);
|
return MP_OBJ_FROM_PTR(t);
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
// return values of mp_vfs_lookup_path
|
// return values of mp_vfs_lookup_path
|
||||||
// ROOT is 0 so that the default current directory is the root directory
|
// ROOT is 0 so that the default current directory is the root directory
|
||||||
#define MP_VFS_NONE ((mp_vfs_mount_t*)1)
|
#define MP_VFS_NONE ((mp_vfs_mount_t *)1)
|
||||||
#define MP_VFS_ROOT ((mp_vfs_mount_t*)0)
|
#define MP_VFS_ROOT ((mp_vfs_mount_t *)0)
|
||||||
|
|
||||||
// MicroPython's port-standardized versions of stat constants
|
// MicroPython's port-standardized versions of stat constants
|
||||||
#define MP_S_IFDIR (0x4000)
|
#define MP_S_IFDIR (0x4000)
|
||||||
|
@ -136,7 +136,7 @@ STATIC mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) {
|
|||||||
if (self->is_str) {
|
if (self->is_str) {
|
||||||
t->items[0] = mp_obj_new_str(fn, strlen(fn));
|
t->items[0] = mp_obj_new_str(fn, strlen(fn));
|
||||||
} else {
|
} else {
|
||||||
t->items[0] = mp_obj_new_bytes((const byte*)fn, strlen(fn));
|
t->items[0] = mp_obj_new_bytes((const byte *)fn, strlen(fn));
|
||||||
}
|
}
|
||||||
if (fno.fattrib & AM_DIR) {
|
if (fno.fattrib & AM_DIR) {
|
||||||
// dir
|
// dir
|
||||||
@ -234,9 +234,9 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_
|
|||||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||||
}
|
}
|
||||||
if ((fno.fattrib & AM_DIR) != 0 &&
|
if ((fno.fattrib & AM_DIR) != 0 &&
|
||||||
strlen(new_path) > strlen(old_path) &&
|
strlen(new_path) > strlen(old_path) &&
|
||||||
new_path[strlen(old_path)] == '/' &&
|
new_path[strlen(old_path)] == '/' &&
|
||||||
strncmp(old_path, new_path, strlen(old_path)) == 0) {
|
strncmp(old_path, new_path, strlen(old_path)) == 0) {
|
||||||
mp_raise_OSError(MP_EINVAL);
|
mp_raise_OSError(MP_EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,11 +324,11 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
|
|||||||
} else {
|
} else {
|
||||||
mode |= MP_S_IFREG;
|
mode |= MP_S_IFREG;
|
||||||
}
|
}
|
||||||
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
|
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
|
||||||
// On non-longint builds, the number of seconds since 1970 (epoch) is too
|
// On non-longint builds, the number of seconds since 1970 (epoch) is too
|
||||||
// large to fit in a smallint, so just return 31-DEC-1999 (0).
|
// large to fit in a smallint, so just return 31-DEC-1999 (0).
|
||||||
mp_obj_t seconds = MP_OBJ_NEW_SMALL_INT(946684800);
|
mp_obj_t seconds = MP_OBJ_NEW_SMALL_INT(946684800);
|
||||||
#else
|
#else
|
||||||
mp_obj_t seconds = mp_obj_new_int_from_uint(
|
mp_obj_t seconds = mp_obj_new_int_from_uint(
|
||||||
timeutils_seconds_since_epoch(
|
timeutils_seconds_since_epoch(
|
||||||
1980 + ((fno.fdate >> 9) & 0x7f),
|
1980 + ((fno.fdate >> 9) & 0x7f),
|
||||||
@ -338,7 +338,7 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
|
|||||||
(fno.ftime >> 5) & 0x3f,
|
(fno.ftime >> 5) & 0x3f,
|
||||||
2 * (fno.ftime & 0x1f)
|
2 * (fno.ftime & 0x1f)
|
||||||
));
|
));
|
||||||
#endif
|
#endif
|
||||||
t->items[0] = MP_OBJ_NEW_SMALL_INT(mode); // st_mode
|
t->items[0] = MP_OBJ_NEW_SMALL_INT(mode); // st_mode
|
||||||
t->items[1] = MP_OBJ_NEW_SMALL_INT(0); // st_ino
|
t->items[1] = MP_OBJ_NEW_SMALL_INT(0); // st_ino
|
||||||
t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // st_dev
|
t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // st_dev
|
||||||
@ -434,7 +434,7 @@ STATIC mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) {
|
|||||||
const char *label_str = mp_obj_str_get_str(label_in);
|
const char *label_str = mp_obj_str_get_str(label_in);
|
||||||
FRESULT res = f_setlabel(&self->fatfs, label_str);
|
FRESULT res = f_setlabel(&self->fatfs, label_str);
|
||||||
if (res != FR_OK) {
|
if (res != FR_OK) {
|
||||||
if(res == FR_WRITE_PROTECTED) {
|
if (res == FR_WRITE_PROTECTED) {
|
||||||
mp_raise_msg(&mp_type_OSError, translate("Read-only filesystem"));
|
mp_raise_msg(&mp_type_OSError, translate("Read-only filesystem"));
|
||||||
}
|
}
|
||||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||||
@ -467,9 +467,9 @@ STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&fat_vfs_statvfs_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&fat_vfs_statvfs_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_fat_mount_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_fat_mount_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&fat_vfs_umount_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&fat_vfs_umount_obj) },
|
||||||
#if MICROPY_FATFS_USE_LABEL
|
#if MICROPY_FATFS_USE_LABEL
|
||||||
{ MP_ROM_QSTR(MP_QSTR_label), MP_ROM_PTR(&fat_vfs_label_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_label), MP_ROM_PTR(&fat_vfs_label_obj) },
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
STATIC MP_DEFINE_CONST_DICT(fat_vfs_locals_dict, fat_vfs_locals_dict_table);
|
STATIC MP_DEFINE_CONST_DICT(fat_vfs_locals_dict, fat_vfs_locals_dict_table);
|
||||||
|
|
||||||
@ -483,7 +483,7 @@ const mp_obj_type_t mp_fat_vfs_type = {
|
|||||||
.name = MP_QSTR_VfsFat,
|
.name = MP_QSTR_VfsFat,
|
||||||
.make_new = fat_vfs_make_new,
|
.make_new = fat_vfs_make_new,
|
||||||
.protocol = &fat_vfs_proto,
|
.protocol = &fat_vfs_proto,
|
||||||
.locals_dict = (mp_obj_dict_t*)&fat_vfs_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&fat_vfs_locals_dict,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,32 +26,31 @@
|
|||||||
|
|
||||||
typedef void *bdev_t;
|
typedef void *bdev_t;
|
||||||
STATIC fs_user_mount_t *disk_get_device(void *bdev) {
|
STATIC fs_user_mount_t *disk_get_device(void *bdev) {
|
||||||
return (fs_user_mount_t*)bdev;
|
return (fs_user_mount_t *)bdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* Read Sector(s) */
|
/* Read Sector(s) */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
DRESULT disk_read (
|
DRESULT disk_read(
|
||||||
bdev_t pdrv, /* Physical drive nmuber (0..) */
|
bdev_t pdrv, /* Physical drive */
|
||||||
BYTE *buff, /* Data buffer to store read data */
|
BYTE *buff, /* Data buffer to store read data */
|
||||||
DWORD sector, /* Sector address (LBA) */
|
DWORD sector, /* Sector address (LBA) */
|
||||||
UINT count /* Number of sectors to read (1..128) */
|
UINT count /* Number of sectors to read (1..128) */
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
fs_user_mount_t *vfs = disk_get_device(pdrv);
|
fs_user_mount_t *vfs = disk_get_device(pdrv);
|
||||||
if (vfs == NULL) {
|
if (vfs == NULL) {
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vfs->flags & FSUSER_NATIVE) {
|
if (vfs->flags & FSUSER_NATIVE) {
|
||||||
mp_uint_t (*f)(uint8_t*, uint32_t, uint32_t) = (void*)(uintptr_t)vfs->readblocks[2];
|
mp_uint_t (*f)(uint8_t *, uint32_t, uint32_t) = (void *)(uintptr_t)vfs->readblocks[2];
|
||||||
if (f(buff, sector, count) != 0) {
|
if (f(buff, sector, count) != 0) {
|
||||||
return RES_ERROR;
|
return RES_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, count * SECSIZE(&vfs->fatfs), buff};
|
mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, count *SECSIZE(&vfs->fatfs), buff};
|
||||||
vfs->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
|
vfs->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
|
||||||
vfs->readblocks[3] = MP_OBJ_FROM_PTR(&ar);
|
vfs->readblocks[3] = MP_OBJ_FROM_PTR(&ar);
|
||||||
nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
@ -74,13 +73,12 @@ DRESULT disk_read (
|
|||||||
/* Write Sector(s) */
|
/* Write Sector(s) */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
DRESULT disk_write (
|
DRESULT disk_write(
|
||||||
bdev_t pdrv, /* Physical drive nmuber (0..) */
|
bdev_t pdrv, /* Physical drive */
|
||||||
const BYTE *buff, /* Data to be written */
|
const BYTE *buff, /* Data to be written */
|
||||||
DWORD sector, /* Sector address (LBA) */
|
DWORD sector, /* Sector address (LBA) */
|
||||||
UINT count /* Number of sectors to write (1..128) */
|
UINT count /* Number of sectors to write (1..128) */
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
fs_user_mount_t *vfs = disk_get_device(pdrv);
|
fs_user_mount_t *vfs = disk_get_device(pdrv);
|
||||||
if (vfs == NULL) {
|
if (vfs == NULL) {
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
@ -92,12 +90,12 @@ DRESULT disk_write (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (vfs->flags & FSUSER_NATIVE) {
|
if (vfs->flags & FSUSER_NATIVE) {
|
||||||
mp_uint_t (*f)(const uint8_t*, uint32_t, uint32_t) = (void*)(uintptr_t)vfs->writeblocks[2];
|
mp_uint_t (*f)(const uint8_t *, uint32_t, uint32_t) = (void *)(uintptr_t)vfs->writeblocks[2];
|
||||||
if (f(buff, sector, count) != 0) {
|
if (f(buff, sector, count) != 0) {
|
||||||
return RES_ERROR;
|
return RES_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, count * SECSIZE(&vfs->fatfs), (void*)buff};
|
mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, count *SECSIZE(&vfs->fatfs), (void *)buff};
|
||||||
vfs->writeblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
|
vfs->writeblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
|
||||||
vfs->writeblocks[3] = MP_OBJ_FROM_PTR(&ar);
|
vfs->writeblocks[3] = MP_OBJ_FROM_PTR(&ar);
|
||||||
nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
@ -121,12 +119,11 @@ DRESULT disk_write (
|
|||||||
/* Miscellaneous Functions */
|
/* Miscellaneous Functions */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
DRESULT disk_ioctl (
|
DRESULT disk_ioctl(
|
||||||
bdev_t pdrv, /* Physical drive nmuber (0..) */
|
bdev_t pdrv, /* Physical drive */
|
||||||
BYTE cmd, /* Control code */
|
BYTE cmd, /* Control code */
|
||||||
void *buff /* Buffer to send/receive control data */
|
void *buff /* Buffer to send/receive control data */
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
fs_user_mount_t *vfs = disk_get_device(pdrv);
|
fs_user_mount_t *vfs = disk_get_device(pdrv);
|
||||||
if (vfs == NULL) {
|
if (vfs == NULL) {
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
@ -145,8 +142,8 @@ DRESULT disk_ioctl (
|
|||||||
uint8_t bp_op = op_map[cmd & 7];
|
uint8_t bp_op = op_map[cmd & 7];
|
||||||
if (bp_op != 0) {
|
if (bp_op != 0) {
|
||||||
if (vfs->flags & FSUSER_NATIVE) {
|
if (vfs->flags & FSUSER_NATIVE) {
|
||||||
bool (*f)(size_t, mp_int_t*) = (void*)(uintptr_t)vfs->u.ioctl[2];
|
bool (*f)(size_t, mp_int_t *) = (void *)(uintptr_t)vfs->u.ioctl[2];
|
||||||
if (!f(bp_op, (mp_int_t*) &out_value)) {
|
if (!f(bp_op, (mp_int_t *)&out_value)) {
|
||||||
return RES_ERROR;
|
return RES_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -190,26 +187,26 @@ DRESULT disk_ioctl (
|
|||||||
return RES_OK;
|
return RES_OK;
|
||||||
|
|
||||||
case GET_SECTOR_COUNT: {
|
case GET_SECTOR_COUNT: {
|
||||||
*((DWORD*)buff) = out_value;
|
*((DWORD *)buff) = out_value;
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case GET_SECTOR_SIZE: {
|
case GET_SECTOR_SIZE: {
|
||||||
if (out_value == 0) {
|
if (out_value == 0) {
|
||||||
// Default sector size
|
// Default sector size
|
||||||
*((WORD*)buff) = 512;
|
*((WORD *)buff) = 512;
|
||||||
} else {
|
} else {
|
||||||
*((WORD*)buff) = out_value;
|
*((WORD *)buff) = out_value;
|
||||||
}
|
}
|
||||||
#if _MAX_SS != _MIN_SS
|
#if _MAX_SS != _MIN_SS
|
||||||
// need to store ssize because we use it in disk_read/disk_write
|
// need to store ssize because we use it in disk_read/disk_write
|
||||||
vfs->fatfs.ssize = *((WORD*)buff);
|
vfs->fatfs.ssize = *((WORD *)buff);
|
||||||
#endif
|
#endif
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case GET_BLOCK_SIZE:
|
case GET_BLOCK_SIZE:
|
||||||
*((DWORD*)buff) = 1; // erase block size in units of sector size
|
*((DWORD *)buff) = 1; // erase block size in units of sector size
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
|
|
||||||
case IOCTL_INIT:
|
case IOCTL_INIT:
|
||||||
@ -223,7 +220,7 @@ DRESULT disk_ioctl (
|
|||||||
} else {
|
} else {
|
||||||
stat = 0;
|
stat = 0;
|
||||||
}
|
}
|
||||||
*((DSTATUS*)buff) = stat;
|
*((DSTATUS *)buff) = stat;
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg,
|
|||||||
pyb_file_obj_t *self = MP_OBJ_TO_PTR(o_in);
|
pyb_file_obj_t *self = MP_OBJ_TO_PTR(o_in);
|
||||||
|
|
||||||
if (request == MP_STREAM_SEEK) {
|
if (request == MP_STREAM_SEEK) {
|
||||||
struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)(uintptr_t)arg;
|
struct mp_stream_seek_t *s = (struct mp_stream_seek_t *)(uintptr_t)arg;
|
||||||
|
|
||||||
switch (s->whence) {
|
switch (s->whence) {
|
||||||
case 0: // SEEK_SET
|
case 0: // SEEK_SET
|
||||||
@ -248,7 +248,7 @@ const mp_obj_type_t mp_type_vfs_fat_fileio = {
|
|||||||
.getiter = mp_identity_getiter,
|
.getiter = mp_identity_getiter,
|
||||||
.iternext = mp_stream_unbuffered_iter,
|
.iternext = mp_stream_unbuffered_iter,
|
||||||
.protocol = &fileio_stream_p,
|
.protocol = &fileio_stream_p,
|
||||||
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ const mp_obj_type_t mp_type_vfs_fat_textio = {
|
|||||||
.getiter = mp_identity_getiter,
|
.getiter = mp_identity_getiter,
|
||||||
.iternext = mp_stream_unbuffered_iter,
|
.iternext = mp_stream_unbuffered_iter,
|
||||||
.protocol = &textio_stream_p,
|
.protocol = &textio_stream_p,
|
||||||
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Factory function for I/O stream classes
|
// Factory function for I/O stream classes
|
||||||
|
@ -42,7 +42,7 @@ STATIC mp_obj_t vfs_posix_get_path_obj(mp_obj_vfs_posix_t *self, mp_obj_t path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (*f)(const char*)) {
|
STATIC mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (*f)(const char *)) {
|
||||||
mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
int ret = f(vfs_posix_get_path_str(self, path_in));
|
int ret = f(vfs_posix_get_path_str(self, path_in));
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@ -168,7 +168,7 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) {
|
|||||||
if (self->is_str) {
|
if (self->is_str) {
|
||||||
t->items[0] = mp_obj_new_str(fn, strlen(fn));
|
t->items[0] = mp_obj_new_str(fn, strlen(fn));
|
||||||
} else {
|
} else {
|
||||||
t->items[0] = mp_obj_new_bytes((const byte*)fn, strlen(fn));
|
t->items[0] = mp_obj_new_bytes((const byte *)fn, strlen(fn));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DIRENT_HAVE_D_TYPE
|
#ifdef _DIRENT_HAVE_D_TYPE
|
||||||
@ -338,7 +338,7 @@ const mp_obj_type_t mp_type_vfs_posix = {
|
|||||||
.name = MP_QSTR_VfsPosix,
|
.name = MP_QSTR_VfsPosix,
|
||||||
.make_new = vfs_posix_make_new,
|
.make_new = vfs_posix_make_new,
|
||||||
.protocol = &vfs_posix_proto,
|
.protocol = &vfs_posix_proto,
|
||||||
.locals_dict = (mp_obj_dict_t*)&vfs_posix_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&vfs_posix_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_VFS_POSIX
|
#endif // MICROPY_VFS_POSIX
|
||||||
|
@ -58,7 +58,7 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_
|
|||||||
case '+':
|
case '+':
|
||||||
mode_rw = O_RDWR;
|
mode_rw = O_RDWR;
|
||||||
break;
|
break;
|
||||||
#if MICROPY_PY_IO_FILEIO
|
#if MICROPY_PY_IO_FILEIO
|
||||||
// If we don't have io.FileIO, then files are in text mode implicitly
|
// If we don't have io.FileIO, then files are in text mode implicitly
|
||||||
case 'b':
|
case 'b':
|
||||||
type = &mp_type_vfs_posix_fileio;
|
type = &mp_type_vfs_posix_fileio;
|
||||||
@ -66,7 +66,7 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_
|
|||||||
case 't':
|
case 't':
|
||||||
type = &mp_type_vfs_posix_textio;
|
type = &mp_type_vfs_posix_textio;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
case MP_STREAM_SEEK: {
|
case MP_STREAM_SEEK: {
|
||||||
struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg;
|
struct mp_stream_seek_t *s = (struct mp_stream_seek_t *)arg;
|
||||||
off_t off = lseek(o->fd, s->offset, s->whence);
|
off_t off = lseek(o->fd, s->offset, s->whence);
|
||||||
if (off == (off_t)-1) {
|
if (off == (off_t)-1) {
|
||||||
*errcode = errno;
|
*errcode = errno;
|
||||||
@ -213,7 +213,7 @@ const mp_obj_type_t mp_type_vfs_posix_fileio = {
|
|||||||
.getiter = mp_identity_getiter,
|
.getiter = mp_identity_getiter,
|
||||||
.iternext = mp_stream_unbuffered_iter,
|
.iternext = mp_stream_unbuffered_iter,
|
||||||
.protocol = &fileio_stream_p,
|
.protocol = &fileio_stream_p,
|
||||||
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -233,10 +233,10 @@ const mp_obj_type_t mp_type_vfs_posix_textio = {
|
|||||||
.getiter = mp_identity_getiter,
|
.getiter = mp_identity_getiter,
|
||||||
.iternext = mp_stream_unbuffered_iter,
|
.iternext = mp_stream_unbuffered_iter,
|
||||||
.protocol = &textio_stream_p,
|
.protocol = &textio_stream_p,
|
||||||
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_textio}, STDIN_FILENO};
|
const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_textio}, STDIN_FILENO};
|
||||||
const mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_textio}, STDOUT_FILENO};
|
const mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_textio}, STDOUT_FILENO};
|
||||||
const mp_obj_vfs_posix_file_t mp_sys_stderr_obj = {{&mp_type_textio}, STDERR_FILENO};
|
const mp_obj_vfs_posix_file_t mp_sys_stderr_obj = {{&mp_type_textio}, STDERR_FILENO};
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ typedef struct _mp_reader_vfs_t {
|
|||||||
} mp_reader_vfs_t;
|
} mp_reader_vfs_t;
|
||||||
|
|
||||||
STATIC mp_uint_t mp_reader_vfs_readbyte(void *data) {
|
STATIC mp_uint_t mp_reader_vfs_readbyte(void *data) {
|
||||||
mp_reader_vfs_t *reader = (mp_reader_vfs_t*)data;
|
mp_reader_vfs_t *reader = (mp_reader_vfs_t *)data;
|
||||||
if (reader->pos >= reader->len) {
|
if (reader->pos >= reader->len) {
|
||||||
if (reader->len < sizeof(reader->buf)) {
|
if (reader->len < sizeof(reader->buf)) {
|
||||||
return MP_READER_EOF;
|
return MP_READER_EOF;
|
||||||
@ -43,7 +43,7 @@ STATIC mp_uint_t mp_reader_vfs_readbyte(void *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void mp_reader_vfs_close(void *data) {
|
STATIC void mp_reader_vfs_close(void *data) {
|
||||||
mp_reader_vfs_t *reader = (mp_reader_vfs_t*)data;
|
mp_reader_vfs_t *reader = (mp_reader_vfs_t *)data;
|
||||||
mp_stream_close(reader->file);
|
mp_stream_close(reader->file);
|
||||||
m_del_obj(mp_reader_vfs_t, reader);
|
m_del_obj(mp_reader_vfs_t, reader);
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ STATIC void mp_reader_vfs_close(void *data) {
|
|||||||
void mp_reader_new_file(mp_reader_t *reader, const char *filename) {
|
void mp_reader_new_file(mp_reader_t *reader, const char *filename) {
|
||||||
mp_reader_vfs_t *rf = m_new_obj(mp_reader_vfs_t);
|
mp_reader_vfs_t *rf = m_new_obj(mp_reader_vfs_t);
|
||||||
mp_obj_t arg = mp_obj_new_str(filename, strlen(filename));
|
mp_obj_t arg = mp_obj_new_str(filename, strlen(filename));
|
||||||
rf->file = mp_vfs_open(1, &arg, (mp_map_t*)&mp_const_empty_map);
|
rf->file = mp_vfs_open(1, &arg, (mp_map_t *)&mp_const_empty_map);
|
||||||
int errcode;
|
int errcode;
|
||||||
rf->len = mp_stream_rw(rf->file, rf->buf, sizeof(rf->buf), &errcode, MP_STREAM_RW_READ | MP_STREAM_RW_ONCE);
|
rf->len = mp_stream_rw(rf->file, rf->buf, sizeof(rf->buf), &errcode, MP_STREAM_RW_READ | MP_STREAM_RW_ONCE);
|
||||||
if (errcode != 0) {
|
if (errcode != 0) {
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
#include "py/proto.h"
|
#include "py/proto.h"
|
||||||
|
|
||||||
int mp_virtual_pin_read(mp_obj_t pin) {
|
int mp_virtual_pin_read(mp_obj_t pin) {
|
||||||
mp_obj_base_t* s = (mp_obj_base_t*)MP_OBJ_TO_PTR(pin);
|
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(pin);
|
||||||
const mp_pin_p_t *pin_p = mp_proto_get(MP_QSTR_protocol_pin, s);
|
const mp_pin_p_t *pin_p = mp_proto_get(MP_QSTR_protocol_pin, s);
|
||||||
return pin_p->ioctl(pin, MP_PIN_READ, 0, NULL);
|
return pin_p->ioctl(pin, MP_PIN_READ, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_virtual_pin_write(mp_obj_t pin, int value) {
|
void mp_virtual_pin_write(mp_obj_t pin, int value) {
|
||||||
mp_obj_base_t* s = (mp_obj_base_t*)MP_OBJ_TO_PTR(pin);
|
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(pin);
|
||||||
const mp_pin_p_t *pin_p = mp_proto_get(MP_QSTR_protocol_pin, s);
|
const mp_pin_p_t *pin_p = mp_proto_get(MP_QSTR_protocol_pin, s);
|
||||||
pin_p->ioctl(pin, MP_PIN_WRITE, value, NULL);
|
pin_p->ioctl(pin, MP_PIN_WRITE, value, NULL);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ void netutils_parse_ipv4_addr(mp_obj_t addr_in, uint8_t *out_ip, netutils_endian
|
|||||||
}
|
}
|
||||||
const char *s = addr_str;
|
const char *s = addr_str;
|
||||||
const char *s_top = addr_str + addr_len;
|
const char *s_top = addr_str + addr_len;
|
||||||
for (mp_uint_t i = 3 ; ; i--) {
|
for (mp_uint_t i = 3; ; i--) {
|
||||||
mp_uint_t val = 0;
|
mp_uint_t val = 0;
|
||||||
for (; s < s_top && *s != '.'; s++) {
|
for (; s < s_top && *s != '.'; s++) {
|
||||||
val = val * 10 + *s - '0';
|
val = val * 10 + *s - '0';
|
||||||
|
@ -36,11 +36,11 @@
|
|||||||
|
|
||||||
#define LEAPOCH ((31 + 29) * 86400)
|
#define LEAPOCH ((31 + 29) * 86400)
|
||||||
|
|
||||||
#define DAYS_PER_400Y (365*400 + 97)
|
#define DAYS_PER_400Y (365 * 400 + 97)
|
||||||
#define DAYS_PER_100Y (365*100 + 24)
|
#define DAYS_PER_100Y (365 * 100 + 24)
|
||||||
#define DAYS_PER_4Y (365*4 + 1)
|
#define DAYS_PER_4Y (365 * 4 + 1)
|
||||||
|
|
||||||
STATIC const uint16_t days_since_jan1[]= { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
|
STATIC const uint16_t days_since_jan1[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
|
||||||
|
|
||||||
bool timeutils_is_leap_year(mp_uint_t year) {
|
bool timeutils_is_leap_year(mp_uint_t year) {
|
||||||
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
|
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
|
||||||
@ -164,7 +164,7 @@ void timeutils_seconds_since_epoch_to_struct_time(mp_uint_t t, timeutils_struct_
|
|||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t timeutils_seconds_since_epoch(mp_uint_t year, mp_uint_t month, mp_uint_t date,
|
mp_uint_t timeutils_seconds_since_epoch(mp_uint_t year, mp_uint_t month, mp_uint_t date,
|
||||||
mp_uint_t hour, mp_uint_t minute, mp_uint_t second) {
|
mp_uint_t hour, mp_uint_t minute, mp_uint_t second) {
|
||||||
mp_uint_t t = timeutils_seconds_since_2000(year, month, date, hour, minute, second);
|
mp_uint_t t = timeutils_seconds_since_2000(year, month, date, hour, minute, second);
|
||||||
return t + EPOCH1970_EPOCH2000_DIFF_SECS;
|
return t + EPOCH1970_EPOCH2000_DIFF_SECS;
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,14 @@
|
|||||||
#define EPOCH1970_EPOCH2000_DIFF_SECS 946684800
|
#define EPOCH1970_EPOCH2000_DIFF_SECS 946684800
|
||||||
|
|
||||||
typedef struct _timeutils_struct_time_t {
|
typedef struct _timeutils_struct_time_t {
|
||||||
uint16_t tm_year; // i.e. 2014
|
uint16_t tm_year; // i.e. 2014
|
||||||
uint8_t tm_mon; // 1..12
|
uint8_t tm_mon; // 1..12
|
||||||
uint8_t tm_mday; // 1..31
|
uint8_t tm_mday; // 1..31
|
||||||
uint8_t tm_hour; // 0..23
|
uint8_t tm_hour; // 0..23
|
||||||
uint8_t tm_min; // 0..59
|
uint8_t tm_min; // 0..59
|
||||||
uint8_t tm_sec; // 0..59
|
uint8_t tm_sec; // 0..59
|
||||||
uint8_t tm_wday; // 0..6 0 = Monday
|
uint8_t tm_wday; // 0..6 0 = Monday
|
||||||
uint16_t tm_yday; // 1..366
|
uint16_t tm_yday; // 1..366
|
||||||
} timeutils_struct_time_t;
|
} timeutils_struct_time_t;
|
||||||
|
|
||||||
bool timeutils_is_leap_year(mp_uint_t year);
|
bool timeutils_is_leap_year(mp_uint_t year);
|
||||||
@ -53,7 +53,7 @@ mp_uint_t timeutils_seconds_since_2000(mp_uint_t year, mp_uint_t month,
|
|||||||
void timeutils_seconds_since_epoch_to_struct_time(mp_uint_t t, timeutils_struct_time_t *tm);
|
void timeutils_seconds_since_epoch_to_struct_time(mp_uint_t t, timeutils_struct_time_t *tm);
|
||||||
|
|
||||||
mp_uint_t timeutils_seconds_since_epoch(mp_uint_t year, mp_uint_t month, mp_uint_t date,
|
mp_uint_t timeutils_seconds_since_epoch(mp_uint_t year, mp_uint_t month, mp_uint_t date,
|
||||||
mp_uint_t hour, mp_uint_t minute, mp_uint_t second);
|
mp_uint_t hour, mp_uint_t minute, mp_uint_t second);
|
||||||
|
|
||||||
mp_uint_t timeutils_mktime(mp_uint_t year, mp_int_t month, mp_int_t mday,
|
mp_uint_t timeutils_mktime(mp_uint_t year, mp_int_t month, mp_int_t mday,
|
||||||
mp_int_t hours, mp_int_t minutes, mp_int_t seconds);
|
mp_int_t hours, mp_int_t minutes, mp_int_t seconds);
|
||||||
|
@ -26,10 +26,10 @@
|
|||||||
|
|
||||||
#include "lib/utils/buffer_helper.h"
|
#include "lib/utils/buffer_helper.h"
|
||||||
|
|
||||||
void normalize_buffer_bounds(int32_t* start, int32_t end, size_t* length) {
|
void normalize_buffer_bounds(int32_t *start, int32_t end, size_t *length) {
|
||||||
if (end < 0) {
|
if (end < 0) {
|
||||||
end += *length;
|
end += *length;
|
||||||
} else if (((size_t) end) > *length) {
|
} else if (((size_t)end) > *length) {
|
||||||
end = *length;
|
end = *length;
|
||||||
}
|
}
|
||||||
if (*start < 0) {
|
if (*start < 0) {
|
||||||
|
@ -30,6 +30,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void normalize_buffer_bounds(int32_t* start, int32_t end, size_t* length);
|
void normalize_buffer_bounds(int32_t *start, int32_t end, size_t *length);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_LIB_UTILS_BUFFER_HELPER_H
|
#endif // MICROPY_INCLUDED_LIB_UTILS_BUFFER_HELPER_H
|
||||||
|
@ -29,6 +29,6 @@
|
|||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
|
|
||||||
STATIC mp_obj_t default___enter__(mp_obj_t self_in) {
|
STATIC mp_obj_t default___enter__(mp_obj_t self_in) {
|
||||||
return self_in;
|
return self_in;
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(default___enter___obj, default___enter__);
|
MP_DEFINE_CONST_FUN_OBJ_1(default___enter___obj, default___enter__);
|
||||||
|
@ -108,7 +108,7 @@ STATIC void strn_print_strn(void *data, const char *str, size_t len) {
|
|||||||
// when linkings against it statically.
|
// when linkings against it statically.
|
||||||
// GCC 9 gives a warning about missing attributes so it's excluded until
|
// GCC 9 gives a warning about missing attributes so it's excluded until
|
||||||
// uClibc+GCC9 support is needed.
|
// uClibc+GCC9 support is needed.
|
||||||
int __GI_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) __attribute__((weak, alias ("vsnprintf")));
|
int __GI_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) __attribute__((weak, alias("vsnprintf")));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) {
|
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) {
|
||||||
@ -134,4 +134,4 @@ int snprintf(char *str, size_t size, const char *fmt, ...) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //MICROPY_USE_INTERNAL_PRINTF
|
#endif // MICROPY_USE_INTERNAL_PRINTF
|
||||||
|
32
lib/utils/pyexec.c
Executable file → Normal file
32
lib/utils/pyexec.c
Executable file → Normal file
@ -85,7 +85,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
|||||||
} else if (exec_flags & EXEC_FLAG_SOURCE_IS_FILENAME) {
|
} else if (exec_flags & EXEC_FLAG_SOURCE_IS_FILENAME) {
|
||||||
lex = mp_lexer_new_from_file(source);
|
lex = mp_lexer_new_from_file(source);
|
||||||
} else {
|
} else {
|
||||||
lex = (mp_lexer_t*)source;
|
lex = (mp_lexer_t *)source;
|
||||||
}
|
}
|
||||||
// source is a lexer, parse and compile the script
|
// source is a lexer, parse and compile the script
|
||||||
qstr source_name = lex->source_name;
|
qstr source_name = lex->source_name;
|
||||||
@ -95,7 +95,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
|||||||
mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
|
mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
|
||||||
module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, exec_flags & EXEC_FLAG_IS_REPL);
|
module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, exec_flags & EXEC_FLAG_IS_REPL);
|
||||||
// Clear the parse tree because it has a heap pointer we don't need anymore.
|
// Clear the parse tree because it has a heap pointer we don't need anymore.
|
||||||
*((uint32_t volatile*) &parse_tree.chunk) = 0;
|
*((uint32_t volatile *)&parse_tree.chunk) = 0;
|
||||||
#else
|
#else
|
||||||
mp_raise_msg(&mp_type_RuntimeError, translate("script compilation not supported"));
|
mp_raise_msg(&mp_type_RuntimeError, translate("script compilation not supported"));
|
||||||
#endif
|
#endif
|
||||||
@ -132,12 +132,12 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
|||||||
if (mp_obj_is_subclass_fast(mp_obj_get_type((mp_obj_t)nlr.ret_val), &mp_type_SystemExit)) {
|
if (mp_obj_is_subclass_fast(mp_obj_get_type((mp_obj_t)nlr.ret_val), &mp_type_SystemExit)) {
|
||||||
// at the moment, the value of SystemExit is unused
|
// at the moment, the value of SystemExit is unused
|
||||||
ret = pyexec_system_exit;
|
ret = pyexec_system_exit;
|
||||||
#if CIRCUITPY_ALARM
|
#if CIRCUITPY_ALARM
|
||||||
} else if (mp_obj_is_subclass_fast(mp_obj_get_type((mp_obj_t)nlr.ret_val), &mp_type_DeepSleepRequest)) {
|
} else if (mp_obj_is_subclass_fast(mp_obj_get_type((mp_obj_t)nlr.ret_val), &mp_type_DeepSleepRequest)) {
|
||||||
ret = PYEXEC_DEEP_SLEEP;
|
ret = PYEXEC_DEEP_SLEEP;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if ((mp_obj_t) nlr.ret_val != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
|
if ((mp_obj_t)nlr.ret_val != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
|
||||||
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
|
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
|
||||||
}
|
}
|
||||||
ret = PYEXEC_EXCEPTION;
|
ret = PYEXEC_EXCEPTION;
|
||||||
@ -169,8 +169,8 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
|||||||
size_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
|
size_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
|
||||||
qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
|
qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
|
||||||
printf("qstr:\n n_pool=" UINT_FMT "\n n_qstr=" UINT_FMT "\n "
|
printf("qstr:\n n_pool=" UINT_FMT "\n n_qstr=" UINT_FMT "\n "
|
||||||
"n_str_data_bytes=" UINT_FMT "\n n_total_bytes=" UINT_FMT "\n",
|
"n_str_data_bytes=" UINT_FMT "\n n_total_bytes=" UINT_FMT "\n",
|
||||||
(unsigned)n_pool, (unsigned)n_qstr, (unsigned)n_str_data_bytes, (unsigned)n_total_bytes);
|
(unsigned)n_pool, (unsigned)n_qstr, (unsigned)n_str_data_bytes, (unsigned)n_total_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MICROPY_ENABLE_GC
|
#if MICROPY_ENABLE_GC
|
||||||
@ -195,7 +195,7 @@ typedef struct _repl_t {
|
|||||||
// but it was moved to MP_STATE_VM(repl_line) as containing
|
// but it was moved to MP_STATE_VM(repl_line) as containing
|
||||||
// root pointer. Still keep structure in case more state
|
// root pointer. Still keep structure in case more state
|
||||||
// will be added later.
|
// will be added later.
|
||||||
//vstr_t line;
|
// vstr_t line;
|
||||||
bool cont_line;
|
bool cont_line;
|
||||||
} repl_t;
|
} repl_t;
|
||||||
|
|
||||||
@ -307,10 +307,10 @@ STATIC int pyexec_friendly_repl_process_char(int c) {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (ret == CHAR_CTRL_C) {
|
if (ret == CHAR_CTRL_C) {
|
||||||
// cancel everything
|
// cancel everything
|
||||||
mp_hal_stdout_tx_str("\r\n");
|
mp_hal_stdout_tx_str("\r\n");
|
||||||
repl.cont_line = false;
|
repl.cont_line = false;
|
||||||
goto input_restart;
|
goto input_restart;
|
||||||
} else if (ret == CHAR_CTRL_D) {
|
} else if (ret == CHAR_CTRL_D) {
|
||||||
// stop entering compound statement
|
// stop entering compound statement
|
||||||
goto exec;
|
goto exec;
|
||||||
@ -326,13 +326,13 @@ STATIC int pyexec_friendly_repl_process_char(int c) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
exec: ;
|
exec:;
|
||||||
int ret = parse_compile_execute(MP_STATE_VM(repl_line), MP_PARSE_SINGLE_INPUT, EXEC_FLAG_ALLOW_DEBUGGING | EXEC_FLAG_IS_REPL | EXEC_FLAG_SOURCE_IS_VSTR, NULL);
|
int ret = parse_compile_execute(MP_STATE_VM(repl_line), MP_PARSE_SINGLE_INPUT, EXEC_FLAG_ALLOW_DEBUGGING | EXEC_FLAG_IS_REPL | EXEC_FLAG_SOURCE_IS_VSTR, NULL);
|
||||||
if (ret & PYEXEC_FORCED_EXIT) {
|
if (ret & PYEXEC_FORCED_EXIT) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_restart:
|
input_restart:
|
||||||
vstr_reset(MP_STATE_VM(repl_line));
|
vstr_reset(MP_STATE_VM(repl_line));
|
||||||
repl.cont_line = false;
|
repl.cont_line = false;
|
||||||
readline_init(MP_STATE_VM(repl_line), ">>> ");
|
readline_init(MP_STATE_VM(repl_line), ">>> ");
|
||||||
@ -409,11 +409,11 @@ int pyexec_friendly_repl(void) {
|
|||||||
vstr_t line;
|
vstr_t line;
|
||||||
vstr_init(&line, 32);
|
vstr_init(&line, 32);
|
||||||
|
|
||||||
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
|
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
|
||||||
// in host mode, we enable the LCD for the repl
|
// in host mode, we enable the LCD for the repl
|
||||||
mp_obj_t lcd_o = mp_call_function_0(mp_load_name(qstr_from_str("LCD")));
|
mp_obj_t lcd_o = mp_call_function_0(mp_load_name(qstr_from_str("LCD")));
|
||||||
mp_call_function_1(mp_load_attr(lcd_o, qstr_from_str("light")), mp_const_true);
|
mp_call_function_1(mp_load_attr(lcd_o, qstr_from_str("light")), mp_const_true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
friendly_repl_reset:
|
friendly_repl_reset:
|
||||||
mp_hal_stdout_tx_str("\r\n");
|
mp_hal_stdout_tx_str("\r\n");
|
||||||
|
@ -35,7 +35,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int return_code;
|
int return_code;
|
||||||
const mp_obj_type_t * exception_type;
|
const mp_obj_type_t *exception_type;
|
||||||
int exception_line;
|
int exception_line;
|
||||||
} pyexec_result_t;
|
} pyexec_result_t;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
|
|||||||
i = 1;
|
i = 1;
|
||||||
}
|
}
|
||||||
// Lump all characters on the next line together.
|
// Lump all characters on the next line together.
|
||||||
while((last_cr || str[i] != '\n') && i < len) {
|
while ((last_cr || str[i] != '\n') && i < len) {
|
||||||
last_cr = str[i] == '\r';
|
last_cr = str[i] == '\r';
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *er
|
|||||||
if (c == '\r') {
|
if (c == '\r') {
|
||||||
c = '\n';
|
c = '\n';
|
||||||
}
|
}
|
||||||
((byte*)buf)[i] = c;
|
((byte *)buf)[i] = c;
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
} else {
|
} else {
|
||||||
@ -87,7 +87,7 @@ STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size,
|
|||||||
|
|
||||||
STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||||
sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
(void) self;
|
(void)self;
|
||||||
|
|
||||||
// For now, pretend we actually flush the stdio stream.
|
// For now, pretend we actually flush the stdio stream.
|
||||||
if (request == MP_STREAM_FLUSH) {
|
if (request == MP_STREAM_FLUSH) {
|
||||||
@ -106,9 +106,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stdio_obj___exit___obj, 4, 4, stdio_o
|
|||||||
// TODO gc hook to close the file if not already closed
|
// TODO gc hook to close the file if not already closed
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = {
|
STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = {
|
||||||
#if MICROPY_PY_SYS_STDIO_BUFFER
|
#if MICROPY_PY_SYS_STDIO_BUFFER
|
||||||
{ MP_ROM_QSTR(MP_QSTR_buffer), MP_ROM_PTR(&stdio_buffer_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_buffer), MP_ROM_PTR(&stdio_buffer_obj) },
|
||||||
#endif
|
#endif
|
||||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj)},
|
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj)},
|
||||||
@ -138,7 +138,7 @@ STATIC const mp_obj_type_t stdio_obj_type = {
|
|||||||
.getiter = mp_identity_getiter,
|
.getiter = mp_identity_getiter,
|
||||||
.iternext = mp_stream_unbuffered_iter,
|
.iternext = mp_stream_unbuffered_iter,
|
||||||
.protocol = &stdio_obj_stream_p,
|
.protocol = &stdio_obj_stream_p,
|
||||||
.locals_dict = (mp_obj_dict_t*)&stdio_locals_dict,
|
.locals_dict = (mp_obj_dict_t *)&stdio_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
const sys_stdio_obj_t mp_sys_stdin_obj = {{&stdio_obj_type}, .fd = STDIO_FD_IN};
|
const sys_stdio_obj_t mp_sys_stdin_obj = {{&stdio_obj_type}, .fd = STDIO_FD_IN};
|
||||||
@ -148,7 +148,7 @@ const sys_stdio_obj_t mp_sys_stderr_obj = {{&stdio_obj_type}, .fd = STDIO_FD_ERR
|
|||||||
#if MICROPY_PY_SYS_STDIO_BUFFER
|
#if MICROPY_PY_SYS_STDIO_BUFFER
|
||||||
STATIC mp_uint_t stdio_buffer_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
STATIC mp_uint_t stdio_buffer_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
||||||
for (uint i = 0; i < size; i++) {
|
for (uint i = 0; i < size; i++) {
|
||||||
((byte*)buf)[i] = mp_hal_stdin_rx_chr();
|
((byte *)buf)[i] = mp_hal_stdin_rx_chr();
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
@ -3695,7 +3695,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ msgstr ""
|
|||||||
#: extmod/moductypes.c ports/atmel-samd/common-hal/pulseio/PulseIn.c
|
#: extmod/moductypes.c ports/atmel-samd/common-hal/pulseio/PulseIn.c
|
||||||
#: ports/cxd56/common-hal/pulseio/PulseIn.c
|
#: ports/cxd56/common-hal/pulseio/PulseIn.c
|
||||||
#: ports/nrf/common-hal/pulseio/PulseIn.c
|
#: ports/nrf/common-hal/pulseio/PulseIn.c
|
||||||
|
#: ports/raspberrypi/common-hal/pulseio/PulseIn.c
|
||||||
#: ports/stm/common-hal/pulseio/PulseIn.c py/obj.c py/objstr.c
|
#: ports/stm/common-hal/pulseio/PulseIn.c py/obj.c py/objstr.c
|
||||||
#: py/objstrunicode.c
|
#: py/objstrunicode.c
|
||||||
msgid "%q index out of range"
|
msgid "%q index out of range"
|
||||||
@ -962,6 +963,7 @@ msgstr ""
|
|||||||
#: ports/cxd56/common-hal/pulseio/PulseIn.c
|
#: ports/cxd56/common-hal/pulseio/PulseIn.c
|
||||||
#: ports/esp32s2/common-hal/pulseio/PulseIn.c
|
#: ports/esp32s2/common-hal/pulseio/PulseIn.c
|
||||||
#: ports/nrf/common-hal/pulseio/PulseIn.c
|
#: ports/nrf/common-hal/pulseio/PulseIn.c
|
||||||
|
#: ports/raspberrypi/common-hal/pulseio/PulseIn.c
|
||||||
#: ports/stm/common-hal/pulseio/PulseIn.c
|
#: ports/stm/common-hal/pulseio/PulseIn.c
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Failed to allocate RX buffer of %d bytes"
|
msgid "Failed to allocate RX buffer of %d bytes"
|
||||||
@ -1247,7 +1249,7 @@ msgstr ""
|
|||||||
msgid "Invalid format chunk size"
|
msgid "Invalid format chunk size"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ports/esp32s2/common-hal/pwmio/PWMOut.c
|
#: ports/esp32s2/common-hal/busio/I2C.c ports/esp32s2/common-hal/pwmio/PWMOut.c
|
||||||
msgid "Invalid frequency"
|
msgid "Invalid frequency"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@ -2291,7 +2293,7 @@ msgstr ""
|
|||||||
msgid "Unsupported format"
|
msgid "Unsupported format"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: py/moduerrno.c
|
#: ports/raspberrypi/common-hal/pulseio/PulseOut.c py/moduerrno.c
|
||||||
msgid "Unsupported operation"
|
msgid "Unsupported operation"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@ -2849,6 +2851,10 @@ msgstr ""
|
|||||||
msgid "differentiation order out of range"
|
msgid "differentiation order out of range"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: extmod/ulab/code/linalg/linalg.c
|
||||||
|
msgid "dimensions do not match"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c
|
#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c
|
||||||
#: shared-bindings/math/__init__.c
|
#: shared-bindings/math/__init__.c
|
||||||
msgid "division by zero"
|
msgid "division by zero"
|
||||||
@ -3339,10 +3345,6 @@ msgstr ""
|
|||||||
msgid "math domain error"
|
msgid "math domain error"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: extmod/ulab/code/linalg/linalg.c
|
|
||||||
msgid "matrix dimensions do not match"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: extmod/ulab/code/linalg/linalg.c
|
#: extmod/ulab/code/linalg/linalg.c
|
||||||
msgid "matrix is not positive definite"
|
msgid "matrix is not positive definite"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@ -3643,7 +3645,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@ -3699,6 +3701,7 @@ msgstr ""
|
|||||||
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
|
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
|
||||||
#: ports/cxd56/common-hal/pulseio/PulseIn.c
|
#: ports/cxd56/common-hal/pulseio/PulseIn.c
|
||||||
#: ports/nrf/common-hal/pulseio/PulseIn.c
|
#: ports/nrf/common-hal/pulseio/PulseIn.c
|
||||||
|
#: ports/raspberrypi/common-hal/pulseio/PulseIn.c
|
||||||
#: ports/stm/common-hal/pulseio/PulseIn.c py/objdict.c py/objlist.c py/objset.c
|
#: ports/stm/common-hal/pulseio/PulseIn.c py/objdict.c py/objlist.c py/objset.c
|
||||||
#: shared-bindings/ps2io/Ps2.c
|
#: shared-bindings/ps2io/Ps2.c
|
||||||
msgid "pop from empty %q"
|
msgid "pop from empty %q"
|
||||||
@ -3724,6 +3727,8 @@ msgstr ""
|
|||||||
#: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h
|
#: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h
|
||||||
#: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h
|
#: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h
|
||||||
#: ports/esp32s2/boards/espressif_saola_1_wrover/mpconfigboard.h
|
#: ports/esp32s2/boards/espressif_saola_1_wrover/mpconfigboard.h
|
||||||
|
#: ports/esp32s2/boards/franzininho_wifi_wroom/mpconfigboard.h
|
||||||
|
#: ports/esp32s2/boards/franzininho_wifi_wrover/mpconfigboard.h
|
||||||
#: ports/esp32s2/boards/lilygo_ttgo_t8_s2_st7789/mpconfigboard.h
|
#: ports/esp32s2/boards/lilygo_ttgo_t8_s2_st7789/mpconfigboard.h
|
||||||
#: ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h
|
#: ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h
|
||||||
#: ports/esp32s2/boards/muselab_nanoesp32_s2/mpconfigboard.h
|
#: ports/esp32s2/boards/muselab_nanoesp32_s2/mpconfigboard.h
|
||||||
@ -4154,10 +4159,6 @@ msgstr ""
|
|||||||
msgid "value_count must be > 0"
|
msgid "value_count must be > 0"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: extmod/ulab/code/linalg/linalg.c
|
|
||||||
msgid "vectors must have same lengths"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: ports/esp32s2/common-hal/alarm/pin/__init__.c
|
#: ports/esp32s2/common-hal/alarm/pin/__init__.c
|
||||||
msgid "wakeup conflict"
|
msgid "wakeup conflict"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -3646,7 +3646,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -3732,7 +3732,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr "Außerhalb des Bereichs der Quelle"
|
msgstr "Außerhalb des Bereichs der Quelle"
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr "Außerhalb des Bereichs des Ziels"
|
msgstr "Außerhalb des Bereichs des Ziels"
|
||||||
|
|
||||||
|
@ -3643,7 +3643,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -3642,7 +3642,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
19
locale/es.po
19
locale/es.po
@ -8,15 +8,15 @@ msgstr ""
|
|||||||
"Project-Id-Version: \n"
|
"Project-Id-Version: \n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
|
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
|
||||||
"PO-Revision-Date: 2021-03-07 15:50+0000\n"
|
"PO-Revision-Date: 2021-03-12 02:03+0000\n"
|
||||||
"Last-Translator: Jose David M <jquintana202020@gmail.com>\n"
|
"Last-Translator: Alvaro Figueroa <alvaro@greencore.co.cr>\n"
|
||||||
"Language-Team: \n"
|
"Language-Team: \n"
|
||||||
"Language: es\n"
|
"Language: es\n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
||||||
"X-Generator: Weblate 4.5.1\n"
|
"X-Generator: Weblate 4.5.2-dev\n"
|
||||||
|
|
||||||
#: main.c
|
#: main.c
|
||||||
msgid ""
|
msgid ""
|
||||||
@ -1836,7 +1836,7 @@ msgstr ""
|
|||||||
|
|
||||||
#: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c
|
#: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c
|
||||||
msgid "Pins must be sequential"
|
msgid "Pins must be sequential"
|
||||||
msgstr ""
|
msgstr "Los pines deben estar en orden secuencial"
|
||||||
|
|
||||||
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
|
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
|
||||||
msgid "Pins must share PWM slice"
|
msgid "Pins must share PWM slice"
|
||||||
@ -2142,11 +2142,10 @@ msgid ""
|
|||||||
"enough power for the whole circuit and press reset (after ejecting "
|
"enough power for the whole circuit and press reset (after ejecting "
|
||||||
"CIRCUITPY).\n"
|
"CIRCUITPY).\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"La alimentación del microntrolador cayó. Asegúrate que tu fuente de "
|
"La alimentación del microntrolador bajó. Asegúrate que tu fuente de "
|
||||||
"alimentación\n"
|
"alimentación\n"
|
||||||
"pueda aportar suficiente energía para todo el circuito y presiona reset "
|
"pueda aportar suficiente energía para todo el circuito y presiona reset "
|
||||||
"(luego de\n"
|
"(luego de expulsar CIRCUITPY)\n"
|
||||||
"expulsar CIRCUITPY)\n"
|
|
||||||
|
|
||||||
#: shared-module/audiomixer/MixerVoice.c
|
#: shared-module/audiomixer/MixerVoice.c
|
||||||
msgid "The sample's bits_per_sample does not match the mixer's"
|
msgid "The sample's bits_per_sample does not match the mixer's"
|
||||||
@ -2818,7 +2817,7 @@ msgstr "circulo solo puede ser registrado con un pariente"
|
|||||||
|
|
||||||
#: shared-bindings/bitmaptools/__init__.c
|
#: shared-bindings/bitmaptools/__init__.c
|
||||||
msgid "clip point must be (x,y) tuple"
|
msgid "clip point must be (x,y) tuple"
|
||||||
msgstr "El punto clip debe ser una tupla (x, y)"
|
msgstr "El punto de recorte debe ser una tupla (x, y)"
|
||||||
|
|
||||||
#: shared-bindings/msgpack/ExtType.c
|
#: shared-bindings/msgpack/ExtType.c
|
||||||
msgid "code outside range 0~127"
|
msgid "code outside range 0~127"
|
||||||
@ -3740,7 +3739,7 @@ msgstr "ord() espera un carácter, pero encontró un string de longitud %d"
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr "fuera de rango de fuente"
|
msgstr "fuera de rango de fuente"
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr "fuera de rango del objetivo"
|
msgstr "fuera de rango del objetivo"
|
||||||
|
|
||||||
@ -3842,7 +3841,7 @@ msgstr "presionando ambos botones al inicio.\n"
|
|||||||
|
|
||||||
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
|
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
|
||||||
msgid "pull masks conflict with direction masks"
|
msgid "pull masks conflict with direction masks"
|
||||||
msgstr ""
|
msgstr "máscara de pull en conflicto con máscara de dirección"
|
||||||
|
|
||||||
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
|
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
|
||||||
msgid "pull_threshold must be between 1 and 32"
|
msgid "pull_threshold must be between 1 and 32"
|
||||||
|
@ -3691,7 +3691,7 @@ msgstr "ord() umaasa ng character pero string ng %d haba ang nakita"
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -8,14 +8,14 @@ msgstr ""
|
|||||||
"Project-Id-Version: 0.1\n"
|
"Project-Id-Version: 0.1\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
|
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
|
||||||
"PO-Revision-Date: 2021-02-21 22:27+0000\n"
|
"PO-Revision-Date: 2021-03-14 23:02+0000\n"
|
||||||
"Last-Translator: Hugo Dahl <hugo@code-jedi.com>\n"
|
"Last-Translator: Hugo Dahl <hugo@code-jedi.com>\n"
|
||||||
"Language: fr\n"
|
"Language: fr\n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=utf-8\n"
|
"Content-Type: text/plain; charset=utf-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
"Plural-Forms: nplurals=2; plural=n > 1;\n"
|
"Plural-Forms: nplurals=2; plural=n > 1;\n"
|
||||||
"X-Generator: Weblate 4.5\n"
|
"X-Generator: Weblate 4.5.2-dev\n"
|
||||||
|
|
||||||
#: main.c
|
#: main.c
|
||||||
msgid ""
|
msgid ""
|
||||||
@ -358,7 +358,7 @@ msgstr "Tous les automates finis sont utilisés"
|
|||||||
|
|
||||||
#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c
|
#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c
|
||||||
msgid "All sync event channels in use"
|
msgid "All sync event channels in use"
|
||||||
msgstr "Tous les canaux d'événements sync (sync event channels) sont utilisés"
|
msgstr "Tout canaux d'événements sync (sync event channels) sont utilisés"
|
||||||
|
|
||||||
#: shared-bindings/pwmio/PWMOut.c
|
#: shared-bindings/pwmio/PWMOut.c
|
||||||
msgid "All timers for this pin are in use"
|
msgid "All timers for this pin are in use"
|
||||||
@ -3760,7 +3760,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr "dépassement des bornes de source"
|
msgstr "dépassement des bornes de source"
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr "dépassement des bornes de target"
|
msgstr "dépassement des bornes de target"
|
||||||
|
|
||||||
|
@ -3643,7 +3643,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -3707,7 +3707,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -3671,7 +3671,7 @@ msgstr "ord()は1文字を要求しますが、長さ %d の文字列が与え
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr "ソースが範囲外"
|
msgstr "ソースが範囲外"
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -3647,7 +3647,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -3704,7 +3704,7 @@ msgstr "ord() verwacht een teken (char) maar vond een string van lengte %d"
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr "buiten bereik van bron"
|
msgstr "buiten bereik van bron"
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr "buiten bereik van doel"
|
msgstr "buiten bereik van doel"
|
||||||
|
|
||||||
|
@ -3664,7 +3664,7 @@ msgstr "ord() oczekuje znaku, a jest łańcuch od długości %d"
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -3749,7 +3749,7 @@ msgstr ""
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr "fora do alcance da fonte"
|
msgstr "fora do alcance da fonte"
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr "fora do alcance do alvo"
|
msgstr "fora do alcance do alvo"
|
||||||
|
|
||||||
|
@ -3707,7 +3707,7 @@ msgstr "ord() förväntade sig ett tecken, men en sträng med längden %d hittad
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr "utanför räckvidd för source"
|
msgstr "utanför räckvidd för source"
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr "utanför räckvidd för target"
|
msgstr "utanför räckvidd för target"
|
||||||
|
|
||||||
|
@ -3704,7 +3704,7 @@ msgstr "ord() yùqí zìfú, dàn chángdù zìfú chuàn %d"
|
|||||||
msgid "out of range of source"
|
msgid "out of range of source"
|
||||||
msgstr "yuán fàn wéi wài"
|
msgstr "yuán fàn wéi wài"
|
||||||
|
|
||||||
#: shared-bindings/displayio/Bitmap.c
|
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
|
||||||
msgid "out of range of target"
|
msgid "out of range of target"
|
||||||
msgstr "mù biāo fàn wéi wài"
|
msgstr "mù biāo fàn wéi wài"
|
||||||
|
|
||||||
|
@ -11,12 +11,12 @@
|
|||||||
// Workaround for setting file translation mode: we must distinguish toolsets
|
// Workaround for setting file translation mode: we must distinguish toolsets
|
||||||
// since mingw has no _set_fmode, and altering msvc's _fmode directly has no effect
|
// since mingw has no _set_fmode, and altering msvc's _fmode directly has no effect
|
||||||
STATIC int set_fmode_impl(int mode) {
|
STATIC int set_fmode_impl(int mode) {
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
_fmode = mode;
|
_fmode = mode;
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
return _set_fmode(mode);
|
return _set_fmode(mode);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_fmode_binary(void) {
|
void set_fmode_binary(void) {
|
||||||
|
@ -28,20 +28,20 @@ STATIC void gc_helper_get_regs(regs_t arr) {
|
|||||||
register long r13 asm ("r13");
|
register long r13 asm ("r13");
|
||||||
register long r14 asm ("r14");
|
register long r14 asm ("r14");
|
||||||
register long r15 asm ("r15");
|
register long r15 asm ("r15");
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
// TODO:
|
// TODO:
|
||||||
// This is dirty workaround for Clang. It tries to get around
|
// This is dirty workaround for Clang. It tries to get around
|
||||||
// uncompliant (wrt to GCC) behavior of handling register variables.
|
// uncompliant (wrt to GCC) behavior of handling register variables.
|
||||||
// Application of this patch here is random, and done only to unbreak
|
// Application of this patch here is random, and done only to unbreak
|
||||||
// MacOS build. Better, cross-arch ways to deal with Clang issues should
|
// MacOS build. Better, cross-arch ways to deal with Clang issues should
|
||||||
// be found.
|
// be found.
|
||||||
asm("" : "=r"(rbx));
|
asm ("" : "=r" (rbx));
|
||||||
asm("" : "=r"(rbp));
|
asm ("" : "=r" (rbp));
|
||||||
asm("" : "=r"(r12));
|
asm ("" : "=r" (r12));
|
||||||
asm("" : "=r"(r13));
|
asm ("" : "=r" (r13));
|
||||||
asm("" : "=r"(r14));
|
asm ("" : "=r" (r14));
|
||||||
asm("" : "=r"(r15));
|
asm ("" : "=r" (r15));
|
||||||
#endif
|
#endif
|
||||||
arr[0] = rbx;
|
arr[0] = rbx;
|
||||||
arr[1] = rbp;
|
arr[1] = rbp;
|
||||||
arr[2] = r12;
|
arr[2] = r12;
|
||||||
@ -120,7 +120,7 @@ void gc_collect(void) {
|
|||||||
regs_t regs;
|
regs_t regs;
|
||||||
gc_helper_get_regs(regs);
|
gc_helper_get_regs(regs);
|
||||||
// GC stack (and regs because we captured them)
|
// GC stack (and regs because we captured them)
|
||||||
void **regs_ptr = (void**)(void*)®s;
|
void **regs_ptr = (void **)(void *)®s;
|
||||||
gc_collect_root(regs_ptr, ((mp_uint_t)MP_STATE_THREAD(stack_top) - (mp_uint_t)®s) / sizeof(mp_uint_t));
|
gc_collect_root(regs_ptr, ((mp_uint_t)MP_STATE_THREAD(stack_top) - (mp_uint_t)®s) / sizeof(mp_uint_t));
|
||||||
#if MICROPY_EMIT_NATIVE
|
#if MICROPY_EMIT_NATIVE
|
||||||
mp_unix_mark_exec();
|
mp_unix_mark_exec();
|
||||||
@ -128,4 +128,4 @@ void gc_collect(void) {
|
|||||||
gc_collect_end();
|
gc_collect_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //MICROPY_ENABLE_GC
|
#endif // MICROPY_ENABLE_GC
|
||||||
|
@ -23,7 +23,7 @@ mp_uint_t mp_verbose_flag = 0;
|
|||||||
|
|
||||||
// Heap size of GC heap (if enabled)
|
// Heap size of GC heap (if enabled)
|
||||||
// Make it larger on a 64 bit machine, because pointers are larger.
|
// Make it larger on a 64 bit machine, because pointers are larger.
|
||||||
long heap_size = 1024*1024 * (sizeof(mp_uint_t) / 4);
|
long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4);
|
||||||
|
|
||||||
STATIC void stderr_print_strn(void *env, const char *str, mp_uint_t len) {
|
STATIC void stderr_print_strn(void *env, const char *str, mp_uint_t len) {
|
||||||
(void)env;
|
(void)env;
|
||||||
@ -77,28 +77,28 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha
|
|||||||
|
|
||||||
STATIC int usage(char **argv) {
|
STATIC int usage(char **argv) {
|
||||||
printf(
|
printf(
|
||||||
"usage: %s [<opts>] [-X <implopt>] <input filename>\n"
|
"usage: %s [<opts>] [-X <implopt>] <input filename>\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"-o : output file for compiled bytecode (defaults to input with .mpy extension)\n"
|
"-o : output file for compiled bytecode (defaults to input with .mpy extension)\n"
|
||||||
"-s : source filename to embed in the compiled bytecode (defaults to input file)\n"
|
"-s : source filename to embed in the compiled bytecode (defaults to input file)\n"
|
||||||
"-v : verbose (trace various operations); can be multiple\n"
|
"-v : verbose (trace various operations); can be multiple\n"
|
||||||
"-O[N] : apply bytecode optimizations of level N\n"
|
"-O[N] : apply bytecode optimizations of level N\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Target specific options:\n"
|
"Target specific options:\n"
|
||||||
"-msmall-int-bits=number : set the maximum bits used to encode a small-int\n"
|
"-msmall-int-bits=number : set the maximum bits used to encode a small-int\n"
|
||||||
"-mno-unicode : don't support unicode in compiled strings\n"
|
"-mno-unicode : don't support unicode in compiled strings\n"
|
||||||
"-mcache-lookup-bc : cache map lookups in the bytecode\n"
|
"-mcache-lookup-bc : cache map lookups in the bytecode\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Implementation specific options:\n", argv[0]
|
"Implementation specific options:\n", argv[0]
|
||||||
);
|
);
|
||||||
int impl_opts_cnt = 0;
|
int impl_opts_cnt = 0;
|
||||||
printf(
|
printf(
|
||||||
" emit={bytecode,native,viper} -- set the default code emitter\n"
|
" emit={bytecode,native,viper} -- set the default code emitter\n"
|
||||||
);
|
);
|
||||||
impl_opts_cnt++;
|
impl_opts_cnt++;
|
||||||
printf(
|
printf(
|
||||||
" heapsize=<n> -- set the heap size for the GC (default %ld)\n"
|
" heapsize=<n> -- set the heap size for the GC (default %ld)\n"
|
||||||
, heap_size);
|
, heap_size);
|
||||||
impl_opts_cnt++;
|
impl_opts_cnt++;
|
||||||
|
|
||||||
if (impl_opts_cnt == 0) {
|
if (impl_opts_cnt == 0) {
|
||||||
@ -162,9 +162,9 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||||||
gc_init(heap, heap + heap_size);
|
gc_init(heap, heap + heap_size);
|
||||||
|
|
||||||
mp_init();
|
mp_init();
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
set_fmode_binary();
|
set_fmode_binary();
|
||||||
#endif
|
#endif
|
||||||
mp_obj_list_init(mp_sys_path, 0);
|
mp_obj_list_init(mp_sys_path, 0);
|
||||||
mp_obj_list_init(mp_sys_argv, 0);
|
mp_obj_list_init(mp_sys_argv, 0);
|
||||||
|
|
||||||
@ -189,7 +189,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||||||
MP_STATE_VM(mp_optimise_value) = argv[a][2] & 0xf;
|
MP_STATE_VM(mp_optimise_value) = argv[a][2] & 0xf;
|
||||||
} else {
|
} else {
|
||||||
MP_STATE_VM(mp_optimise_value) = 0;
|
MP_STATE_VM(mp_optimise_value) = 0;
|
||||||
for (char *p = argv[a] + 1; *p && *p == 'O'; p++, MP_STATE_VM(mp_optimise_value)++);
|
for (char *p = argv[a] + 1; *p && *p == 'O'; p++, MP_STATE_VM(mp_optimise_value)++) {;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[a], "-o") == 0) {
|
} else if (strcmp(argv[a], "-o") == 0) {
|
||||||
if (a + 1 >= argc) {
|
if (a + 1 >= argc) {
|
||||||
@ -264,6 +265,6 @@ void nlr_jump_fail(void *val) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_write(const char* text) {
|
void serial_write(const char *text) {
|
||||||
printf("%s", text);
|
printf("%s", text);
|
||||||
}
|
}
|
||||||
|
@ -68,45 +68,45 @@
|
|||||||
// MINGW only handles these errno names.
|
// MINGW only handles these errno names.
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#define MICROPY_PY_UERRNO_LIST \
|
#define MICROPY_PY_UERRNO_LIST \
|
||||||
X(EPERM) \
|
X(EPERM) \
|
||||||
X(ENOENT) \
|
X(ENOENT) \
|
||||||
X(ESRCH) \
|
X(ESRCH) \
|
||||||
X(EINTR) \
|
X(EINTR) \
|
||||||
X(EIO) \
|
X(EIO) \
|
||||||
X(ENXIO) \
|
X(ENXIO) \
|
||||||
X(E2BIG) \
|
X(E2BIG) \
|
||||||
X(ENOEXEC) \
|
X(ENOEXEC) \
|
||||||
X(EBADF) \
|
X(EBADF) \
|
||||||
X(ECHILD) \
|
X(ECHILD) \
|
||||||
X(EAGAIN) \
|
X(EAGAIN) \
|
||||||
X(ENOMEM) \
|
X(ENOMEM) \
|
||||||
X(EACCES) \
|
X(EACCES) \
|
||||||
X(EFAULT) \
|
X(EFAULT) \
|
||||||
X(EBUSY) \
|
X(EBUSY) \
|
||||||
X(EEXIST) \
|
X(EEXIST) \
|
||||||
X(EXDEV) \
|
X(EXDEV) \
|
||||||
X(ENODEV) \
|
X(ENODEV) \
|
||||||
X(ENOTDIR) \
|
X(ENOTDIR) \
|
||||||
X(EISDIR) \
|
X(EISDIR) \
|
||||||
X(EINVAL) \
|
X(EINVAL) \
|
||||||
X(ENFILE) \
|
X(ENFILE) \
|
||||||
X(EMFILE) \
|
X(EMFILE) \
|
||||||
X(ENOTTY) \
|
X(ENOTTY) \
|
||||||
X(EFBIG) \
|
X(EFBIG) \
|
||||||
X(ENOSPC) \
|
X(ENOSPC) \
|
||||||
X(ESPIPE) \
|
X(ESPIPE) \
|
||||||
X(EROFS) \
|
X(EROFS) \
|
||||||
X(EMLINK) \
|
X(EMLINK) \
|
||||||
X(EPIPE) \
|
X(EPIPE) \
|
||||||
X(EDOM) \
|
X(EDOM) \
|
||||||
X(ERANGE) \
|
X(ERANGE) \
|
||||||
X(EDEADLOCK) \
|
X(EDEADLOCK) \
|
||||||
X(EDEADLK) \
|
X(EDEADLK) \
|
||||||
X(ENAMETOOLONG) \
|
X(ENAMETOOLONG) \
|
||||||
X(ENOLCK) \
|
X(ENOLCK) \
|
||||||
X(ENOSYS) \
|
X(ENOSYS) \
|
||||||
X(ENOTEMPTY) \
|
X(ENOTEMPTY) \
|
||||||
X(EILSEQ)
|
X(EILSEQ)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// type definitions for the specific machine
|
// type definitions for the specific machine
|
||||||
@ -114,7 +114,7 @@
|
|||||||
#ifdef __LP64__
|
#ifdef __LP64__
|
||||||
typedef long mp_int_t; // must be pointer size
|
typedef long mp_int_t; // must be pointer size
|
||||||
typedef unsigned long mp_uint_t; // must be pointer size
|
typedef unsigned long mp_uint_t; // must be pointer size
|
||||||
#elif defined ( __MINGW32__ ) && defined( _WIN64 )
|
#elif defined(__MINGW32__) && defined(_WIN64)
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
typedef __int64 mp_int_t;
|
typedef __int64 mp_int_t;
|
||||||
typedef unsigned __int64 mp_uint_t;
|
typedef unsigned __int64 mp_uint_t;
|
||||||
@ -141,7 +141,7 @@ typedef long mp_off_t;
|
|||||||
// We need to provide a declaration/definition of alloca()
|
// We need to provide a declaration/definition of alloca()
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#elif defined( _WIN32 )
|
#elif defined(_WIN32)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#else
|
#else
|
||||||
#include <alloca.h>
|
#include <alloca.h>
|
||||||
|
@ -93,8 +93,8 @@
|
|||||||
#endif
|
#endif
|
||||||
// </h>
|
// </h>
|
||||||
|
|
||||||
//<h> Generic Clock Generator Division
|
// <h> Generic Clock Generator Division
|
||||||
//<o> Generic clock generator 0 division <0x0000-0xFFFF>
|
// <o> Generic clock generator 0 division <0x0000-0xFFFF>
|
||||||
// <i>
|
// <i>
|
||||||
// <id> gclk_gen_0_div
|
// <id> gclk_gen_0_div
|
||||||
#ifndef CONF_GCLK_GEN_0_DIV
|
#ifndef CONF_GCLK_GEN_0_DIV
|
||||||
@ -177,8 +177,8 @@
|
|||||||
#endif
|
#endif
|
||||||
// </h>
|
// </h>
|
||||||
|
|
||||||
//<h> Generic Clock Generator Division
|
// <h> Generic Clock Generator Division
|
||||||
//<o> Generic clock generator 1 division <0x0000-0xFFFF>
|
// <o> Generic clock generator 1 division <0x0000-0xFFFF>
|
||||||
// <i>
|
// <i>
|
||||||
// <id> gclk_gen_1_div
|
// <id> gclk_gen_1_div
|
||||||
#ifndef CONF_GCLK_GEN_1_DIV
|
#ifndef CONF_GCLK_GEN_1_DIV
|
||||||
@ -263,8 +263,8 @@
|
|||||||
#endif
|
#endif
|
||||||
// </h>
|
// </h>
|
||||||
|
|
||||||
//<h> Generic Clock Generator Division
|
// <h> Generic Clock Generator Division
|
||||||
//<o> Generic clock generator 2 division <0x0000-0xFFFF>
|
// <o> Generic clock generator 2 division <0x0000-0xFFFF>
|
||||||
// <i>
|
// <i>
|
||||||
// <id> gclk_gen_2_div
|
// <id> gclk_gen_2_div
|
||||||
#ifndef CONF_GCLK_GEN_2_DIV
|
#ifndef CONF_GCLK_GEN_2_DIV
|
||||||
@ -349,8 +349,8 @@
|
|||||||
#endif
|
#endif
|
||||||
// </h>
|
// </h>
|
||||||
|
|
||||||
//<h> Generic Clock Generator Division
|
// <h> Generic Clock Generator Division
|
||||||
//<o> Generic clock generator 3 division <0x0000-0xFFFF>
|
// <o> Generic clock generator 3 division <0x0000-0xFFFF>
|
||||||
// <i>
|
// <i>
|
||||||
// <id> gclk_gen_3_div
|
// <id> gclk_gen_3_div
|
||||||
#ifndef CONF_GCLK_GEN_3_DIV
|
#ifndef CONF_GCLK_GEN_3_DIV
|
||||||
@ -435,8 +435,8 @@
|
|||||||
#endif
|
#endif
|
||||||
// </h>
|
// </h>
|
||||||
|
|
||||||
//<h> Generic Clock Generator Division
|
// <h> Generic Clock Generator Division
|
||||||
//<o> Generic clock generator 4 division <0x0000-0xFFFF>
|
// <o> Generic clock generator 4 division <0x0000-0xFFFF>
|
||||||
// <i>
|
// <i>
|
||||||
// <id> gclk_gen_4_div
|
// <id> gclk_gen_4_div
|
||||||
#ifndef CONF_GCLK_GEN_4_DIV
|
#ifndef CONF_GCLK_GEN_4_DIV
|
||||||
@ -521,8 +521,8 @@
|
|||||||
#endif
|
#endif
|
||||||
// </h>
|
// </h>
|
||||||
|
|
||||||
//<h> Generic Clock Generator Division
|
// <h> Generic Clock Generator Division
|
||||||
//<o> Generic clock generator 5 division <0x0000-0xFFFF>
|
// <o> Generic clock generator 5 division <0x0000-0xFFFF>
|
||||||
// <i>
|
// <i>
|
||||||
// <id> gclk_gen_5_div
|
// <id> gclk_gen_5_div
|
||||||
#ifndef CONF_GCLK_GEN_5_DIV
|
#ifndef CONF_GCLK_GEN_5_DIV
|
||||||
@ -607,8 +607,8 @@
|
|||||||
#endif
|
#endif
|
||||||
// </h>
|
// </h>
|
||||||
|
|
||||||
//<h> Generic Clock Generator Division
|
// <h> Generic Clock Generator Division
|
||||||
//<o> Generic clock generator 6 division <0x0000-0xFFFF>
|
// <o> Generic clock generator 6 division <0x0000-0xFFFF>
|
||||||
// <i>
|
// <i>
|
||||||
// <id> gclk_gen_6_div
|
// <id> gclk_gen_6_div
|
||||||
#ifndef CONF_GCLK_GEN_6_DIV
|
#ifndef CONF_GCLK_GEN_6_DIV
|
||||||
@ -693,8 +693,8 @@
|
|||||||
#endif
|
#endif
|
||||||
// </h>
|
// </h>
|
||||||
|
|
||||||
//<h> Generic Clock Generator Division
|
// <h> Generic Clock Generator Division
|
||||||
//<o> Generic clock generator 7 division <0x0000-0xFFFF>
|
// <o> Generic clock generator 7 division <0x0000-0xFFFF>
|
||||||
// <i>
|
// <i>
|
||||||
// <id> gclk_gen_7_div
|
// <id> gclk_gen_7_div
|
||||||
#ifndef CONF_GCLK_GEN_7_DIV
|
#ifndef CONF_GCLK_GEN_7_DIV
|
||||||
|
@ -294,12 +294,12 @@
|
|||||||
// BAUD: register value low [7:0]
|
// BAUD: register value low [7:0]
|
||||||
// BAUDLOW: register value high [15:8], only used for odd BAUD + BAUDLOW
|
// BAUDLOW: register value high [15:8], only used for odd BAUD + BAUDLOW
|
||||||
#define CONF_SERCOM_1_I2CM_BAUD_BAUDLOW \
|
#define CONF_SERCOM_1_I2CM_BAUD_BAUDLOW \
|
||||||
(((CONF_GCLK_SERCOM1_CORE_FREQUENCY - (CONF_SERCOM_1_I2CM_BAUD * 10) \
|
(((CONF_GCLK_SERCOM1_CORE_FREQUENCY - (CONF_SERCOM_1_I2CM_BAUD * 10) \
|
||||||
- (CONF_SERCOM_1_I2CM_TRISE * (CONF_SERCOM_1_I2CM_BAUD / 100) * (CONF_GCLK_SERCOM1_CORE_FREQUENCY / 10000) \
|
- (CONF_SERCOM_1_I2CM_TRISE * (CONF_SERCOM_1_I2CM_BAUD / 100) * (CONF_GCLK_SERCOM1_CORE_FREQUENCY / 10000) \
|
||||||
/ 1000)) \
|
/ 1000)) \
|
||||||
* 10 \
|
* 10 \
|
||||||
+ 5) \
|
+ 5) \
|
||||||
/ (CONF_SERCOM_1_I2CM_BAUD * 10))
|
/ (CONF_SERCOM_1_I2CM_BAUD * 10))
|
||||||
#ifndef CONF_SERCOM_1_I2CM_BAUD_RATE
|
#ifndef CONF_SERCOM_1_I2CM_BAUD_RATE
|
||||||
#if CONF_SERCOM_1_I2CM_BAUD_BAUDLOW > (0xFF * 2)
|
#if CONF_SERCOM_1_I2CM_BAUD_BAUDLOW > (0xFF * 2)
|
||||||
#warning Requested I2C baudrate too low, please check
|
#warning Requested I2C baudrate too low, please check
|
||||||
@ -309,9 +309,9 @@
|
|||||||
#define CONF_SERCOM_1_I2CM_BAUD_RATE 1
|
#define CONF_SERCOM_1_I2CM_BAUD_RATE 1
|
||||||
#else
|
#else
|
||||||
#define CONF_SERCOM_1_I2CM_BAUD_RATE \
|
#define CONF_SERCOM_1_I2CM_BAUD_RATE \
|
||||||
((CONF_SERCOM_1_I2CM_BAUD_BAUDLOW & 0x1) \
|
((CONF_SERCOM_1_I2CM_BAUD_BAUDLOW & 0x1) \
|
||||||
? (CONF_SERCOM_1_I2CM_BAUD_BAUDLOW / 2) + ((CONF_SERCOM_1_I2CM_BAUD_BAUDLOW / 2 + 1) << 8) \
|
? (CONF_SERCOM_1_I2CM_BAUD_BAUDLOW / 2) + ((CONF_SERCOM_1_I2CM_BAUD_BAUDLOW / 2 + 1) << 8) \
|
||||||
: (CONF_SERCOM_1_I2CM_BAUD_BAUDLOW / 2))
|
: (CONF_SERCOM_1_I2CM_BAUD_BAUDLOW / 2))
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -506,7 +506,7 @@
|
|||||||
#if CONF_SERCOM_2_USART_SAMPR == 0
|
#if CONF_SERCOM_2_USART_SAMPR == 0
|
||||||
#ifndef CONF_SERCOM_2_USART_BAUD_RATE
|
#ifndef CONF_SERCOM_2_USART_BAUD_RATE
|
||||||
#define CONF_SERCOM_2_USART_BAUD_RATE \
|
#define CONF_SERCOM_2_USART_BAUD_RATE \
|
||||||
65536 - ((65536 * 16.0f * CONF_SERCOM_2_USART_BAUD) / CONF_GCLK_SERCOM2_CORE_FREQUENCY)
|
65536 - ((65536 * 16.0f * CONF_SERCOM_2_USART_BAUD) / CONF_GCLK_SERCOM2_CORE_FREQUENCY)
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH
|
#ifndef CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH
|
||||||
#define CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH 0
|
#define CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH 0
|
||||||
@ -514,7 +514,7 @@
|
|||||||
#elif CONF_SERCOM_2_USART_SAMPR == 1
|
#elif CONF_SERCOM_2_USART_SAMPR == 1
|
||||||
#ifndef CONF_SERCOM_2_USART_BAUD_RATE
|
#ifndef CONF_SERCOM_2_USART_BAUD_RATE
|
||||||
#define CONF_SERCOM_2_USART_BAUD_RATE \
|
#define CONF_SERCOM_2_USART_BAUD_RATE \
|
||||||
((CONF_GCLK_SERCOM2_CORE_FREQUENCY) / (CONF_SERCOM_2_USART_BAUD * 16)) - (CONF_SERCOM_2_USART_FRACTIONAL / 8)
|
((CONF_GCLK_SERCOM2_CORE_FREQUENCY) / (CONF_SERCOM_2_USART_BAUD * 16)) - (CONF_SERCOM_2_USART_FRACTIONAL / 8)
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH
|
#ifndef CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH
|
||||||
#define CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH 0
|
#define CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH 0
|
||||||
@ -522,7 +522,7 @@
|
|||||||
#elif CONF_SERCOM_2_USART_SAMPR == 2
|
#elif CONF_SERCOM_2_USART_SAMPR == 2
|
||||||
#ifndef CONF_SERCOM_2_USART_BAUD_RATE
|
#ifndef CONF_SERCOM_2_USART_BAUD_RATE
|
||||||
#define CONF_SERCOM_2_USART_BAUD_RATE \
|
#define CONF_SERCOM_2_USART_BAUD_RATE \
|
||||||
65536 - ((65536 * 8.0f * CONF_SERCOM_2_USART_BAUD) / CONF_GCLK_SERCOM2_CORE_FREQUENCY)
|
65536 - ((65536 * 8.0f * CONF_SERCOM_2_USART_BAUD) / CONF_GCLK_SERCOM2_CORE_FREQUENCY)
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH
|
#ifndef CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH
|
||||||
#define CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH 0
|
#define CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH 0
|
||||||
@ -530,7 +530,7 @@
|
|||||||
#elif CONF_SERCOM_2_USART_SAMPR == 3
|
#elif CONF_SERCOM_2_USART_SAMPR == 3
|
||||||
#ifndef CONF_SERCOM_2_USART_BAUD_RATE
|
#ifndef CONF_SERCOM_2_USART_BAUD_RATE
|
||||||
#define CONF_SERCOM_2_USART_BAUD_RATE \
|
#define CONF_SERCOM_2_USART_BAUD_RATE \
|
||||||
((CONF_GCLK_SERCOM2_CORE_FREQUENCY) / (CONF_SERCOM_2_USART_BAUD * 8)) - (CONF_SERCOM_2_USART_FRACTIONAL / 8)
|
((CONF_GCLK_SERCOM2_CORE_FREQUENCY) / (CONF_SERCOM_2_USART_BAUD * 8)) - (CONF_SERCOM_2_USART_FRACTIONAL / 8)
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH
|
#ifndef CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH
|
||||||
#define CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH 0
|
#define CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH 0
|
||||||
@ -538,7 +538,7 @@
|
|||||||
#elif CONF_SERCOM_2_USART_SAMPR == 4
|
#elif CONF_SERCOM_2_USART_SAMPR == 4
|
||||||
#ifndef CONF_SERCOM_2_USART_BAUD_RATE
|
#ifndef CONF_SERCOM_2_USART_BAUD_RATE
|
||||||
#define CONF_SERCOM_2_USART_BAUD_RATE \
|
#define CONF_SERCOM_2_USART_BAUD_RATE \
|
||||||
65536 - ((65536 * 3.0f * CONF_SERCOM_2_USART_BAUD) / CONF_GCLK_SERCOM2_CORE_FREQUENCY)
|
65536 - ((65536 * 3.0f * CONF_SERCOM_2_USART_BAUD) / CONF_GCLK_SERCOM2_CORE_FREQUENCY)
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH
|
#ifndef CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH
|
||||||
#define CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH 0
|
#define CONF_SERCOM_2_USART_RECEIVE_PULSE_LENGTH 0
|
||||||
@ -552,9 +552,9 @@
|
|||||||
#define CONF_SERCOM_3_SPI_ENABLE 1
|
#define CONF_SERCOM_3_SPI_ENABLE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//<o> SPI DMA TX Channel <0-32>
|
// <o> SPI DMA TX Channel <0-32>
|
||||||
//<i> This defines DMA channel to be used
|
// <i> This defines DMA channel to be used
|
||||||
//<id> spi_master_dma_tx_channel
|
// <id> spi_master_dma_tx_channel
|
||||||
#ifndef CONF_SERCOM_3_SPI_M_DMA_TX_CHANNEL
|
#ifndef CONF_SERCOM_3_SPI_M_DMA_TX_CHANNEL
|
||||||
#define CONF_SERCOM_3_SPI_M_DMA_TX_CHANNEL 0
|
#define CONF_SERCOM_3_SPI_M_DMA_TX_CHANNEL 0
|
||||||
#endif
|
#endif
|
||||||
@ -565,9 +565,9 @@
|
|||||||
#define CONF_SERCOM_3_SPI_RX_CHANNEL 1
|
#define CONF_SERCOM_3_SPI_RX_CHANNEL 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//<o> DMA Channel <0-32>
|
// <o> DMA Channel <0-32>
|
||||||
//<i> This defines DMA channel to be used
|
// <i> This defines DMA channel to be used
|
||||||
//<id> spi_master_dma_rx_channel
|
// <id> spi_master_dma_rx_channel
|
||||||
#ifndef CONF_SERCOM_3_SPI_M_DMA_RX_CHANNEL
|
#ifndef CONF_SERCOM_3_SPI_M_DMA_RX_CHANNEL
|
||||||
#define CONF_SERCOM_3_SPI_M_DMA_RX_CHANNEL 1
|
#define CONF_SERCOM_3_SPI_M_DMA_RX_CHANNEL 1
|
||||||
#endif
|
#endif
|
||||||
|
@ -95,7 +95,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// <o>Osc Calibration Value <0-65535>
|
// <o>Osc Calibration Value <0-65535>
|
||||||
// <i> Set the Oscillator Calibration Value
|
// <i> Set the Oscillator Calibration Value
|
||||||
// <i> Default: 1
|
// <i> Default: 1
|
||||||
// <id> osc8m_arch_calib
|
// <id> osc8m_arch_calib
|
||||||
#ifndef CONF_OSC8M_CALIB
|
#ifndef CONF_OSC8M_CALIB
|
||||||
@ -183,7 +183,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// <o>Osc Calibration Value <0-65535>
|
// <o>Osc Calibration Value <0-65535>
|
||||||
// <i> Set the Oscillator Calibration Value
|
// <i> Set the Oscillator Calibration Value
|
||||||
// <i> Default: 0
|
// <i> Default: 0
|
||||||
// <id> osc32k_arch_calib
|
// <id> osc32k_arch_calib
|
||||||
#ifndef CONF_OSC32K_CALIB
|
#ifndef CONF_OSC32K_CALIB
|
||||||
@ -396,7 +396,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// <o>Osc Calibration Value <0-255>
|
// <o>Osc Calibration Value <0-255>
|
||||||
// <i> Set the Oscillator Calibration Value
|
// <i> Set the Oscillator Calibration Value
|
||||||
// <i> Default: 0
|
// <i> Default: 0
|
||||||
// <id> osculp32k_arch_calib
|
// <id> osculp32k_arch_calib
|
||||||
#ifndef CONF_OSCULP32K_CALIB
|
#ifndef CONF_OSCULP32K_CALIB
|
||||||
@ -536,7 +536,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// <o>DFLL Multiply Factor<0-65535>
|
// <o>DFLL Multiply Factor<0-65535>
|
||||||
// <i> Set the DFLL Multiply Factor
|
// <i> Set the DFLL Multiply Factor
|
||||||
// <i> Default: 0
|
// <i> Default: 0
|
||||||
// <id> dfll48m_mul
|
// <id> dfll48m_mul
|
||||||
#ifndef CONF_DFLL_MUL
|
#ifndef CONF_DFLL_MUL
|
||||||
@ -564,17 +564,17 @@
|
|||||||
|
|
||||||
#if CONF_DFLL_OVERWRITE_CALIBRATION == 0
|
#if CONF_DFLL_OVERWRITE_CALIBRATION == 0
|
||||||
#define CONF_DEFAULT_CORASE \
|
#define CONF_DEFAULT_CORASE \
|
||||||
((FUSES_DFLL48M_COARSE_CAL_Msk & (*((uint32_t *)FUSES_DFLL48M_COARSE_CAL_ADDR))) >> FUSES_DFLL48M_COARSE_CAL_Pos)
|
((FUSES_DFLL48M_COARSE_CAL_Msk & (*((uint32_t *)FUSES_DFLL48M_COARSE_CAL_ADDR))) >> FUSES_DFLL48M_COARSE_CAL_Pos)
|
||||||
|
|
||||||
#define CONF_DFLLVAL \
|
#define CONF_DFLLVAL \
|
||||||
SYSCTRL_DFLLVAL_COARSE(((CONF_DEFAULT_CORASE) == 0x3F) ? 0x1F : (CONF_DEFAULT_CORASE)) \
|
SYSCTRL_DFLLVAL_COARSE(((CONF_DEFAULT_CORASE) == 0x3F) ? 0x1F : (CONF_DEFAULT_CORASE)) \
|
||||||
| SYSCTRL_DFLLVAL_FINE(512)
|
| SYSCTRL_DFLLVAL_FINE(512)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define CONF_DFLLVAL SYSCTRL_DFLLVAL_COARSE(CONF_DFLL_COARSE) | SYSCTRL_DFLLVAL_FINE(CONF_DFLL_FINE)
|
#define CONF_DFLLVAL SYSCTRL_DFLLVAL_COARSE(CONF_DFLL_COARSE) | SYSCTRL_DFLLVAL_FINE(CONF_DFLL_FINE)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
//</e>
|
// </e>
|
||||||
|
|
||||||
// </h>
|
// </h>
|
||||||
// </e>
|
// </e>
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#define CONF_TC3_PRESCALER TC_CTRLA_PRESCALER_DIV8_Val
|
#define CONF_TC3_PRESCALER TC_CTRLA_PRESCALER_DIV8_Val
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//<o> Period Value <0x00000000-0xFFFFFFFF>
|
// <o> Period Value <0x00000000-0xFFFFFFFF>
|
||||||
// <id> tc_per
|
// <id> tc_per
|
||||||
#ifndef CONF_TC3_PER
|
#ifndef CONF_TC3_PER
|
||||||
#define CONF_TC3_PER 0x32
|
#define CONF_TC3_PER 0x32
|
||||||
@ -52,7 +52,7 @@
|
|||||||
/* Caculate pwm ccx register value based on WAVE_PER_VAL and Waveform Duty Value */
|
/* Caculate pwm ccx register value based on WAVE_PER_VAL and Waveform Duty Value */
|
||||||
#if CONF_TC3_PRESCALER < TC_CTRLA_PRESCALER_DIV64_Val
|
#if CONF_TC3_PRESCALER < TC_CTRLA_PRESCALER_DIV64_Val
|
||||||
#define CONF_TC3_CC0 \
|
#define CONF_TC3_CC0 \
|
||||||
((uint32_t)(((double)CONF_TC3_WAVE_PER_VAL * CONF_GCLK_TC3_FREQUENCY) / 1000000 / (1 << CONF_TC3_PRESCALER) - 1))
|
((uint32_t)(((double)CONF_TC3_WAVE_PER_VAL * CONF_GCLK_TC3_FREQUENCY) / 1000000 / (1 << CONF_TC3_PRESCALER) - 1))
|
||||||
#define CONF_TC3_CC1 ((CONF_TC3_CC0 * CONF_TC3_WAVE_DUTY_VAL) / 1000)
|
#define CONF_TC3_CC1 ((CONF_TC3_CC0 * CONF_TC3_WAVE_DUTY_VAL) / 1000)
|
||||||
|
|
||||||
#elif CONF_TC3_PRESCALER == TC_CTRLA_PRESCALER_DIV64_Val
|
#elif CONF_TC3_PRESCALER == TC_CTRLA_PRESCALER_DIV64_Val
|
||||||
@ -83,7 +83,7 @@
|
|||||||
|
|
||||||
// <h> Advanced settings
|
// <h> Advanced settings
|
||||||
/* Commented intentionally. Timer uses fixed value. May be used by other abstractions based on TC. */
|
/* Commented intentionally. Timer uses fixed value. May be used by other abstractions based on TC. */
|
||||||
//#define CONF_TC3_WAVEGEN TC_CTRLA_WAVEGEN_MFRQ_Val
|
// #define CONF_TC3_WAVEGEN TC_CTRLA_WAVEGEN_MFRQ_Val
|
||||||
|
|
||||||
// <q> Run in standby
|
// <q> Run in standby
|
||||||
// <i> Indicates whether the will continue running in standby sleep mode or not
|
// <i> Indicates whether the will continue running in standby sleep mode or not
|
||||||
@ -103,14 +103,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Commented intentionally. Timer uses fixed value. May be used by other abstractions based on TC. */
|
/* Commented intentionally. Timer uses fixed value. May be used by other abstractions based on TC. */
|
||||||
//#define CONF_TC3_DIR 0
|
// #define CONF_TC3_DIR 0
|
||||||
//#define CONF_TC3_ONESHOT 0
|
// #define CONF_TC3_ONESHOT 0
|
||||||
|
|
||||||
/* Commented intentionally. Timer uses fixed value. May be used by other abstractions based on TC. */
|
/* Commented intentionally. Timer uses fixed value. May be used by other abstractions based on TC. */
|
||||||
//#define CONF_TC3_INVEN0 0
|
// #define CONF_TC3_INVEN0 0
|
||||||
//#define CONF_TC3_INVEN1 0
|
// #define CONF_TC3_INVEN1 0
|
||||||
//#define CONF_TC3_CPTEN0 0
|
// #define CONF_TC3_CPTEN0 0
|
||||||
//#define CONF_TC3_CPTEN1 0
|
// #define CONF_TC3_CPTEN1 0
|
||||||
|
|
||||||
// <q> Debug Running Mode
|
// <q> Debug Running Mode
|
||||||
// <i> Indicates whether the Debug Running Mode is enabled or not
|
// <i> Indicates whether the Debug Running Mode is enabled or not
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user