From e85289081198a7b3c04401f8fa1e65b418f91c43 Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Sun, 14 Jun 2020 18:36:44 +0200 Subject: [PATCH] feat(mp): Enable (u)bluetooth module using stubs --- lib/micropython/meson.build | 1 + pycardium/meson.build | 3 +- pycardium/modules/modbluetooth_card10.c | 171 ++++++++++++++++++++++++ pycardium/mpconfigport.h | 1 + 4 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 pycardium/modules/modbluetooth_card10.c diff --git a/lib/micropython/meson.build b/lib/micropython/meson.build index 4777aa4e8..bf021db1a 100644 --- a/lib/micropython/meson.build +++ b/lib/micropython/meson.build @@ -182,6 +182,7 @@ micropython_additional_sources = files( micropython_extmod_sources = files( 'micropython/extmod/utime_mphal.c', + 'micropython/extmod/modbluetooth.c', 'micropython/extmod/modbtree.c', 'micropython/extmod/modframebuf.c', 'micropython/extmod/modubinascii.c', diff --git a/pycardium/meson.build b/pycardium/meson.build index bd01afb49..a8e410e85 100644 --- a/pycardium/meson.build +++ b/pycardium/meson.build @@ -11,6 +11,7 @@ modsrc = files( 'modules/light_sensor.c', 'modules/max30001-sys.c', 'modules/max86150.c', + 'modules/modbluetooth_card10.c', 'modules/os.c', 'modules/personal_state.c', 'modules/power.c', @@ -20,7 +21,7 @@ modsrc = files( 'modules/sys_leds.c', 'modules/utime.c', 'modules/vibra.c', - 'modules/ws2812.c' + 'modules/ws2812.c', ) ################################# diff --git a/pycardium/modules/modbluetooth_card10.c b/pycardium/modules/modbluetooth_card10.c new file mode 100644 index 000000000..e3ba0bc93 --- /dev/null +++ b/pycardium/modules/modbluetooth_card10.c @@ -0,0 +1,171 @@ +#include "extmod/modbluetooth.h" +#include <stdint.h> + +// Enables the Bluetooth stack. +int mp_bluetooth_init(void) +{ + return 0; +} + +// Disables the Bluetooth stack. Is a no-op when not enabled. +void mp_bluetooth_deinit(void) +{ +} + +// Returns true when the Bluetooth stack is enabled. +bool mp_bluetooth_is_enabled(void) +{ + return false; +} + +// Gets the MAC addr of this device in big-endian format. +void mp_bluetooth_get_device_addr(uint8_t *addr) +{ +} + +// Start advertisement. Will re-start advertisement when already enabled. +// Returns errno on failure. +int mp_bluetooth_gap_advertise_start( + bool connectable, + int32_t interval_us, + const uint8_t *adv_data, + size_t adv_data_len, + const uint8_t *sr_data, + size_t sr_data_len +) { + return 0; +} + +// Stop advertisement. No-op when already stopped. +void mp_bluetooth_gap_advertise_stop(void) +{ +} + +// Start adding services. Must be called before mp_bluetooth_register_service. +int mp_bluetooth_gatts_register_service_begin(bool append) +{ + return 0; +} +// // Add a service with the given list of characteristics to the queue to be registered. +// The value_handles won't be valid until after mp_bluetooth_register_service_end is called. +int mp_bluetooth_gatts_register_service( + mp_obj_bluetooth_uuid_t *service_uuid, + mp_obj_bluetooth_uuid_t **characteristic_uuids, + uint8_t *characteristic_flags, + mp_obj_bluetooth_uuid_t **descriptor_uuids, + uint8_t *descriptor_flags, + uint8_t *num_descriptors, + uint16_t *handles, + size_t num_characteristics +) { + return 0; +} +// Register any queued services. +int mp_bluetooth_gatts_register_service_end() +{ + return 0; +} + +// Read the value from the local gatts db (likely this has been written by a central). +int mp_bluetooth_gatts_read( + uint16_t value_handle, uint8_t **value, size_t *value_len +) { + return 0; +} +// Write a value to the local gatts db (ready to be queried by a central). +int mp_bluetooth_gatts_write( + uint16_t value_handle, const uint8_t *value, size_t value_len +) { + return 0; +} +// Notify the central that it should do a read. +int mp_bluetooth_gatts_notify(uint16_t conn_handle, uint16_t value_handle) +{ + return 0; +} +// Notify the central, including a data payload. (Note: does not set the gatts db value). +int mp_bluetooth_gatts_notify_send( + uint16_t conn_handle, + uint16_t value_handle, + const uint8_t *value, + size_t *value_len +) { + return 0; +} +// Indicate the central. +int mp_bluetooth_gatts_indicate(uint16_t conn_handle, uint16_t value_handle) +{ + return 0; +} + +// Resize and enable/disable append-mode on a value. +// Append-mode means that remote writes will append and local reads will clear after reading. +int mp_bluetooth_gatts_set_buffer(uint16_t value_handle, size_t len, bool append) +{ + return 0; +} + +// Disconnect from a central or peripheral. +int mp_bluetooth_gap_disconnect(uint16_t conn_handle) +{ + return 0; +} + +#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE +// Start a discovery (scan). Set duration to zero to run continuously. +int mp_bluetooth_gap_scan_start( + int32_t duration_ms, int32_t interval_us, int32_t window_us +) { + return 0; +} + +// Stop discovery (if currently active). +int mp_bluetooth_gap_scan_stop(void) +{ + return 0; +} + +// Connect to a found peripheral. +int mp_bluetooth_gap_peripheral_connect( + uint8_t addr_type, const uint8_t *addr, int32_t duration_ms +) { + return 0; +} + +// Find all primary services on the connected peripheral. +int mp_bluetooth_gattc_discover_primary_services(uint16_t conn_handle) +{ + return 0; +} + +// Find all characteristics on the specified service on a connected peripheral. +int mp_bluetooth_gattc_discover_characteristics( + uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle +) { + return 0; +} + +// Find all descriptors on the specified characteristic on a connected peripheral. +int mp_bluetooth_gattc_discover_descriptors( + uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle +) { + return 0; +} + +// Initiate read of a value from the remote peripheral. +int mp_bluetooth_gattc_read(uint16_t conn_handle, uint16_t value_handle) +{ + return 0; +} + +// Write the value to the remote peripheral. +int mp_bluetooth_gattc_write( + uint16_t conn_handle, + uint16_t value_handle, + const uint8_t *value, + size_t *value_len, + unsigned int mode +) { + return 0; +} +#endif diff --git a/pycardium/mpconfigport.h b/pycardium/mpconfigport.h index 7a57e34f6..cfc5a8a33 100644 --- a/pycardium/mpconfigport.h +++ b/pycardium/mpconfigport.h @@ -52,6 +52,7 @@ int mp_hal_trng_read_int(void); #define MICROPY_PY_IO_FILEIO (1) #define MICROPY_PY_UERRNO (1) #define MICROPY_PY_FRAMEBUF (1) +#define MICROPY_PY_BLUETOOTH (1) /* Modules */ #define MODULE_BHI160_ENABLED (1) -- GitLab