From c8956037d81e70664539257e8ec549400be9d88a Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Mon, 23 Jan 2017 13:41:09 +0000 Subject: [PATCH 01/13] relay: Fix get relay 1 state function Signed-off-by: Francois Berder --- letmecreate/click/relay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/letmecreate/click/relay.py b/letmecreate/click/relay.py index a83b275..d9a3f86 100644 --- a/letmecreate/click/relay.py +++ b/letmecreate/click/relay.py @@ -50,7 +50,7 @@ def get_relay_1_state(mikrobus_index): Note: An exception is thrown if it fails to set state of relay 1. """ state = ctypes.c_uint8(0) - ret = _LIB.relay_click_set_relay_1_state(mikrobus_index, + ret = _LIB.relay_click_get_relay_1_state(mikrobus_index, ctypes.byref(state)) if ret < 0: raise Exception("relay click get relay 1 state") From 236960afae05e08130a5c64a8d57247b4c35114b Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Fri, 3 Feb 2017 16:56:00 +0000 Subject: [PATCH 02/13] i2c: add timeout feature Signed-off-by: Francois Berder --- letmecreate/core/i2c.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/letmecreate/core/i2c.py b/letmecreate/core/i2c.py index 0fd5c4e..bf8e6a1 100644 --- a/letmecreate/core/i2c.py +++ b/letmecreate/core/i2c.py @@ -9,7 +9,8 @@ def init(): """Initialise I2C bus on both mikrobus. - The current I2C bus is set to MIKROBUS_1. + The current I2C bus is set to MIKROBUS_1. The timeout is disabled for + both busses. Note: If an error occurs during the initialisation, an exception is thrown. """ @@ -98,6 +99,18 @@ def read_byte(slave_address): return data.value +def get_timeout(): + """Returns the timeout in milliseconds of the current bus.""" + return _LIB.i2c_get_timeout() + + +def set_timeout(timeout): + """Set the timeout in milliseconds of the current bus. + Set timeout to 0 disables it. + """ + _LIB.i2c_set_timeout(timeout) + + def release(): """Release I2C bus on both mikrobus. From a71500691e3989cd321014fdc69d1cb3a91c2476 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Fri, 3 Feb 2017 16:56:45 +0000 Subject: [PATCH 03/13] alphanum: Remove select display functions/add release function Signed-off-by: Francois Berder --- letmecreate/click/alphanum.py | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/letmecreate/click/alphanum.py b/letmecreate/click/alphanum.py index a828be0..c034a1a 100644 --- a/letmecreate/click/alphanum.py +++ b/letmecreate/click/alphanum.py @@ -66,25 +66,8 @@ def raw_write(a, b): raise Exception("alphanum click raw write failed") -def select_left_display(): - """Select left display. - - This function will enable the left display and disable the right display. - - Note: An exception is thrown if it fails to select the left display. - """ - ret = _LIB.alphanum_click_select_left_display() - if ret < 0: - raise Exception("alphanum click select left display failed") - - -def select_right_display(): - """Select right display. - - This function will enable the right display and disable the left display. - - Note: An exception is thrown if it fails to select the right display. - """ - ret = _LIB.alphanum_click_select_right_display() +def release(): + """Stop refreshing display""" + ret = _LIB.alphanum_click_release() if ret < 0: - raise Exception("alphanum click select right display failed") + raise Exception("alphanum click release failed") From f9c79b98d687a9f75022677f4631e75d066c1cc4 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Fri, 3 Feb 2017 17:03:34 +0000 Subject: [PATCH 04/13] gpio: Add get_pin function Signed-off-by: Francois Berder --- letmecreate/core/gpio.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/letmecreate/core/gpio.py b/letmecreate/core/gpio.py index 0df7e84..dcc7f53 100644 --- a/letmecreate/core/gpio.py +++ b/letmecreate/core/gpio.py @@ -5,6 +5,13 @@ _LIB = ctypes.CDLL('libletmecreate_core.so') +# Pin type +TYPE_AN = 0 +TYPE_RST = 1 +TYPE_PWM = 2 +TYPE_INT = 3 +TYPE_COUNT = 4 + # GPIO pin number MIKROBUS_1_AN = 22 MIKROBUS_1_RST = 23 @@ -52,6 +59,18 @@ def init(gpio_pin): raise Exception("gpio init failed") +def get_pin(mikrobus_index, pin_type): + """Returns GPIO index of a pin on provided mikrobus + + Note: An exception is thrown if the gpio cannot be found. + """ + pin = ctypes.c_uint8(0) + ret = _LIB.gpio_get_pin(mikrobus_index, pin_type, ctypes.byref(pin)) + if ret < 0: + raise Exception("gpio get pin failed") + return pin.value + + def set_direction(gpio_pin, direction): """Configure GPIO as an input or an output. From 7980a0ecec34564829a13bda0271cadb9ebaad3a Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Fri, 3 Feb 2017 17:05:35 +0000 Subject: [PATCH 05/13] core_common: Add MIKROBUS_COUNT and check_valid_mikrobus Signed-off-by: Francois Berder --- letmecreate/core/common.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/letmecreate/core/common.py b/letmecreate/core/common.py index 97d2452..9edcfec 100644 --- a/letmecreate/core/common.py +++ b/letmecreate/core/common.py @@ -1,5 +1,17 @@ #!/usr/bin/env python3 """Define constants for mikrobus index.""" +import ctypes + +_LIB = ctypes.CDLL('libletmecreate_core.so') + MIKROBUS_1 = 0 MIKROBUS_2 = 1 +MIKROBUS_COUNT = 2 + + +def check_valid_mikrobus(mikrobus_index): + """Check if mikrobus exists + Returns 0 if succesful, -1 otherwise. + """ + return _LIB.check_valid_mikrobus(mikrobus_index) From cdbf31d056f1991b5206a4f42f2ab129f800e7a7 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Fri, 3 Feb 2017 17:08:54 +0000 Subject: [PATCH 06/13] spi: Add get_maximum_transfer_length function Signed-off-by: Francois Berder --- letmecreate/core/spi.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/letmecreate/core/spi.py b/letmecreate/core/spi.py index 3f56e78..decd39f 100644 --- a/letmecreate/core/spi.py +++ b/letmecreate/core/spi.py @@ -98,6 +98,18 @@ def transfer(tx_data): return [rx_buffer[i] for i in range(length)] +def get_maximum_tranfer_length(): + """Returns maximum length of a transfer in bytes. + + Note: An exception is thrown if it fails to find the limit. + """ + transfer_length_limit = ctypes.c_uint32(0) + ret = _LIB.spi_get_maximum_tranfer_length(ctypes.byref(transfer_length_limit)) + if ret < 0: + raise Exception("spi get maximum tranfer length failed") + return transfer_length_limit.value + + def release(): """Release all SPI bus. From afb22c19277a221e011aa89c65e4716bf1304c41 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Wed, 8 Feb 2017 11:53:33 +0000 Subject: [PATCH 07/13] alphanum: Synchronize example with LetMeCreate Signed-off-by: Francois Berder --- examples/alphanum_example.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/examples/alphanum_example.py b/examples/alphanum_example.py index dd8bf75..3c1227a 100755 --- a/examples/alphanum_example.py +++ b/examples/alphanum_example.py @@ -2,10 +2,8 @@ """This example shows how to use the Alphanum Click wrapper of the LetMeCreate to display characters. -It displays "Ci" using both displays by enabling them one after the other at -100Hz to give the illusion that both characters are displayed at the same -time. The user has to interrupt the program to exit it by pressing Ctrl+C. - * +It displays "Ci" during 5 seconds + The Alphanum Click must be inserted in Mikrobus 1 before running this program. """ @@ -13,15 +11,14 @@ from letmecreate.core.common import MIKROBUS_1 from letmecreate.core import spi from letmecreate.click import alphanum -import time +from time import sleep spi.init() alphanum.init(MIKROBUS_1) alphanum.write('C', 'i') -while True: - alphanum.select_left_display() - time.sleep(0.01) - alphanum.select_right_display() - time.sleep(0.01) +sleep(5) + +alphanum.release() +spi.release() From 3fca19aa37923bdc57518f76fc5145c14a16ef73 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Wed, 8 Feb 2017 13:53:11 +0000 Subject: [PATCH 08/13] lora: Add python binding Signed-off-by: Francois Berder --- letmecreate/click/__init__.py | 3 +- letmecreate/click/lora.py | 110 ++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 letmecreate/click/lora.py diff --git a/letmecreate/click/__init__.py b/letmecreate/click/__init__.py index 280adf4..bcf7c81 100644 --- a/letmecreate/click/__init__.py +++ b/letmecreate/click/__init__.py @@ -19,6 +19,7 @@ - Joystick - Light - LIN Hall + - Lora - Motion - Oled - Proximity @@ -32,6 +33,6 @@ __all__ = ['seven_seg', 'led_matrix', 'accel', 'adc', 'air_quality', 'alcohol', 'bargraph', 'CO', 'color', 'color2', 'eve', 'fan', 'gyro', - 'ir_distance', 'ir_eclipse', 'joystick', 'light', 'lin_hall', + 'ir_distance', 'ir_eclipse', 'joystick', 'light', 'lin_hall', 'lora', 'motion', 'oled', 'proximity', 'relay', 'relay2', 'relay4', 'rtc', 'thermo3', 'uni_hall'] diff --git a/letmecreate/click/lora.py b/letmecreate/click/lora.py new file mode 100644 index 0000000..1cc40b7 --- /dev/null +++ b/letmecreate/click/lora.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +"""Python binding of Lora wrapper of LetMeCreate library.""" + +import ctypes + +LORA_CLICK_AUTO_FREQ_BAND_250KHZ = 0 +LORA_CLICK_AUTO_FREQ_BAND_125KHZ = 1 +LORA_CLICK_AUTO_FREQ_BAND_62_5KHZ = 2 +LORA_CLICK_AUTO_FREQ_BAND_31_3KHZ = 3 +LORA_CLICK_AUTO_FREQ_BAND_15_6KHZ = 4 +LORA_CLICK_AUTO_FREQ_BAND_7_8KHZ = 5 +LORA_CLICK_AUTO_FREQ_BAND_3_9KHZ = 6 +LORA_CLICK_AUTO_FREQ_BAND_200KHZ = 7 +LORA_CLICK_AUTO_FREQ_BAND_100KHZ = 8 +LORA_CLICK_AUTO_FREQ_BAND_50KHZ = 9 +LORA_CLICK_AUTO_FREQ_BAND_25KHZ = 10 +LORA_CLICK_AUTO_FREQ_BAND_12_5KHZ = 11 +LORA_CLICK_AUTO_FREQ_BAND_6_3KHZ = 12 +LORA_CLICK_AUTO_FREQ_BAND_3_1KHZ = 13 +LORA_CLICK_AUTO_FREQ_BAND_166_7KHZ = 14 +LORA_CLICK_AUTO_FREQ_BAND_83_3KHZ = 15 +LORA_CLICK_AUTO_FREQ_BAND_41_7KHZ = 16 +LORA_CLICK_AUTO_FREQ_BAND_20_8KHZ = 17 +LORA_CLICK_AUTO_FREQ_BAND_10_4KHZ = 18 +LORA_CLICK_AUTO_FREQ_BAND_5_2KHZ = 19 +LORA_CLICK_AUTO_FREQ_BAND_2_6KHZ = 20 +LORA_CLICK_AUTO_FREQ_BAND_COUNT = 21 + +LORA_CLICK_CODING_RATE_4_5 = 0 +LORA_CLICK_CODING_RATE_4_6 = 1 +LORA_CLICK_CODING_RATE_4_7 = 2 +LORA_CLICK_CODING_RATE_4_8 = 3 +LORA_CLICK_CODING_RATE_COUNT = 4 + +LORA_CLICK_BANDWIDTH_125KHZ = 0 +LORA_CLICK_BANDWIDTH_250KHZ = 1 +LORA_CLICK_BANDWIDTH_500KHZ = 2 + +class LoraClickConfig(ctypes.Structure): + _fields_ = [ + ("frequency", ctypes.c_uint32), + ("spreading_factor", ctypes.c_uint8), + ("auto_freq_band", ctypes.c_uint), + ("coding_rate", ctypes.c_uint), + ("bandwidth", ctypes.c_uint), + ("power", ctypes.c_int8), + ("bitrate", ctypes.c_uint16), + ("freq_deviation", ctypes.c_uint16), + ("preamble_length", ctypes.c_uint16), + ("enable_crc_header", ctypes.c_bool)] + +_LIB = ctypes.CDLL('libletmecreate_click.so') + +_LIB.lora_click_get_default_configuration.restype = LoraClickConfig + +def get_default_configuration(): + """Returns default configuration.""" + return _LIB.lora_click_get_default_configuration() + + +def init(mikrobus_index, config): + ret = _LIB.lora_click_init(mikrobus_index, config) + if ret < 0: + raise Exception("") + + +def configure(config): + ret = _LIB.lora_click_configure(config) + if ret < 0: + raise Exception("") + + +def send(data): + length = len(data) + tx_buffer = (ctypes.c_uint8 * length)(*data) + ret = _LIB.lora_click_send(tx_buffer, length) + if ret < 0: + raise Exception("") + + +def receive(length): + rx_buffer = (ctypes.c_uint8 * length)() + ret = _LIB.lora_click_receive(rx_buffer, length) + if ret < 0: + raise Exception("") + return [rx_buffer[i] for i in range(length)] + + +def write_eeprom(start_address, data): + length = len(data) + tmp = (ctypes.c_uint8 * length)(*data) + ret = _LIB.lora_click_write_eeprom(start_address, tmp, length) + if ret < 0: + raise Exception("") + + +def read_eeprom(start_address, length): + data = (ctypes.c_uint8 * length)() + ret = _LIB.lora_click_read_eeprom(start_address, data, length) + if ret < 0: + raise Exception("") + return [data[i] for i in range(length)] + + +def get_eui(): + eui = (ctypes.c_uint8 * 8)() + ret = _LIB.lora_click_get_eui(eui) + if ret < 0: + raise Exception("") + return [eui[i] for i in range(8)] From bf2c44dd8f07ec101d68513016ce2786bf1b6694 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Wed, 8 Feb 2017 13:54:31 +0000 Subject: [PATCH 09/13] click: init: Fix bad CO variable Signed-off-by: Francois Berder --- letmecreate/click/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/letmecreate/click/__init__.py b/letmecreate/click/__init__.py index bcf7c81..560cfb4 100644 --- a/letmecreate/click/__init__.py +++ b/letmecreate/click/__init__.py @@ -32,7 +32,7 @@ """ __all__ = ['seven_seg', 'led_matrix', 'accel', 'adc', 'air_quality', 'alcohol', - 'bargraph', 'CO', 'color', 'color2', 'eve', 'fan', 'gyro', + 'bargraph', 'co', 'color', 'color2', 'eve', 'fan', 'gyro', 'ir_distance', 'ir_eclipse', 'joystick', 'light', 'lin_hall', 'lora', 'motion', 'oled', 'proximity', 'relay', 'relay2', 'relay4', 'rtc', 'thermo3', 'uni_hall'] From 25dbc125181267afa08d6a6702a8a4ee73f8c7f1 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Thu, 9 Feb 2017 15:06:04 +0000 Subject: [PATCH 10/13] lora: Add example Signed-off-by: Francois Berder --- examples/lora_example.py | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 examples/lora_example.py diff --git a/examples/lora_example.py b/examples/lora_example.py new file mode 100755 index 0000000..139896c --- /dev/null +++ b/examples/lora_example.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +"""This example shows how to use the Lora Click wrapper of the LetMeCreate to +send or receive data. + +Depending on the mode selected, it either continuously sends a message every +second, or it waits for data and prints what it receives. +The user has to interrupt the program to exit it by pressing Ctrl+C. + +To run the example in send mode: +$ ./lora_example.py s + +To run the example in receive mode: +$ ./lora_example.py r + +The Lora Click must be inserted in Mikrobus 1 before running this program. +""" + +from letmecreate.core.common import MIKROBUS_1 +from letmecreate.click import lora +from letmecreate.core import uart +from letmecreate.core.uart import UART_BD_57600 +from time import sleep +import sys + +def receive(): + buffer = lora.receive(16) + buffer = bytes(buffer).decode('utf-8') + print(buffer) + +def send(n): + buffer = 'Hello, World! {}'.format(n) + lora.send(buffer.encode('utf-8')) + print(buffer) + +if len(sys.argv) < 2: + print('{} (r|s)'.format(sys.argv[0])) + sys.exit(-1) + +mode = sys.argv[1] +if mode != 'r' and mode != 's': + print('Invalid mode.') + sys.exit(-1) + +print('Press Ctrl+C to exit program') + +uart.init() +uart.select_bus(MIKROBUS_1) +uart.set_baudrate(UART_BD_57600) + +config = lora.get_default_configuration() +lora.init(MIKROBUS_1, config) + +n = 0 +while True: + if mode == 's': + send(n) + sleep(1) + elif mode == 'r': + receive() + + n += 1 + + +uart.release() From 689af763d7d51a9ff86590d4f37f1ad5da6c261d Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Thu, 9 Feb 2017 15:14:46 +0000 Subject: [PATCH 11/13] lora: Add documentation Signed-off-by: Francois Berder --- letmecreate/click/lora.py | 66 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/letmecreate/click/lora.py b/letmecreate/click/lora.py index 1cc40b7..6e3d9c7 100644 --- a/letmecreate/click/lora.py +++ b/letmecreate/click/lora.py @@ -37,6 +37,7 @@ LORA_CLICK_BANDWIDTH_500KHZ = 2 class LoraClickConfig(ctypes.Structure): + """Lora Click configuration""" _fields_ = [ ("frequency", ctypes.c_uint32), ("spreading_factor", ctypes.c_uint8), @@ -54,23 +55,56 @@ class LoraClickConfig(ctypes.Structure): _LIB.lora_click_get_default_configuration.restype = LoraClickConfig def get_default_configuration(): - """Returns default configuration.""" + """Returns default configuration: + + frequency = 868000000 + spreading_factor = 12 + auto_freq_band = LORA_CLICK_AUTO_FREQ_BAND_125KHZ + coding_rate = LORA_CLICK_CODING_RATE_4_8 + bandwidth = LORA_CLICK_BANDWIDTH_250KHZ + power = 14 + bitrate = 5000 + freq_deviation = 5000 + preamble_length = 8 + enable_crc_header = true + """ return _LIB.lora_click_get_default_configuration() def init(mikrobus_index, config): + """Initialize the Lora Click and configure it. + + mikrobus_index: 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + config: Configuration of the Lora Click + + Note: An exception is thrown if it fails to initialize the Lora Click. + """ ret = _LIB.lora_click_init(mikrobus_index, config) if ret < 0: raise Exception("") def configure(config): + """Configure the Lora Click + + config: Configuration of the Lora Click + + Note: An exception is thrown if it fails to configure the Lora Click. + """ ret = _LIB.lora_click_configure(config) if ret < 0: raise Exception("") def send(data): + """Send a list of bytes + + data: list of bytes + + This is a blocking call. + + Note: An exception is thrown if it fails to send all bytes. + """ length = len(data) tx_buffer = (ctypes.c_uint8 * length)(*data) ret = _LIB.lora_click_send(tx_buffer, length) @@ -79,6 +113,15 @@ def send(data): def receive(length): + """Receive a list of bytes + + length: Number of bytes to receive + + This is a blocking call, it will not return until the number of requested + bytes has been received. + + Note: An exception is thrown if it fails to receive all bytes. + """ rx_buffer = (ctypes.c_uint8 * length)() ret = _LIB.lora_click_receive(rx_buffer, length) if ret < 0: @@ -87,6 +130,13 @@ def receive(length): def write_eeprom(start_address, data): + """Write some bytes in EEPROM + + start_address: Must be in range 0x300-0x3FF + data: A list of bytes to write + + Note: An exception is thrown if it fails to write bytes to the EEPROM. + """ length = len(data) tmp = (ctypes.c_uint8 * length)(*data) ret = _LIB.lora_click_write_eeprom(start_address, tmp, length) @@ -95,6 +145,13 @@ def write_eeprom(start_address, data): def read_eeprom(start_address, length): + """Read a list of bytes from EEPROM + + start_address: Must be in range 0x300-0x3FF + length: Number of bytes to read + + Note: An exception is thrown if it fails to read bytes from the EEPROM. + """ data = (ctypes.c_uint8 * length)() ret = _LIB.lora_click_read_eeprom(start_address, data, length) if ret < 0: @@ -103,6 +160,13 @@ def read_eeprom(start_address, length): def get_eui(): + """Read the EUI from the Lora Click + + This function returns a list of 8 bytes representing the EUI of the + device. + + Note: An exception is thrown if it fails to read the EUI. + """ eui = (ctypes.c_uint8 * 8)() ret = _LIB.lora_click_get_eui(eui) if ret < 0: From 0cb903d0aa64cb8af9f4c3eaeec0cfe56543ba99 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Tue, 14 Feb 2017 10:46:18 +0000 Subject: [PATCH 12/13] uni_hall: Add example Signed-off-by: Francois Berder --- examples/uni_hall_example.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 examples/uni_hall_example.py diff --git a/examples/uni_hall_example.py b/examples/uni_hall_example.py new file mode 100755 index 0000000..8b2c910 --- /dev/null +++ b/examples/uni_hall_example.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +"""This example shows how to use the UNI Hall Click binding of LetMeCreate. +""" + +from letmecreate.click import uni_hall +from letmecreate.core.common import MIKROBUS_1 +from letmecreate.core.gpio_monitor import GPIO_FALLING, GPIO_RAISING +from time import sleep + + +def print_hello(arg): + if arg == GPIO_FALLING: + print("Hello, starts dectecting north pole.") + elif arg == GPIO_RAISING: + print("Hello, stops dectecting north pole.") + +uni_hall.attach_callback(MIKROBUS_1, print_hello) +print("Callback is now active for 15 seconds.") +print("Move the north pole of a magnet over the sensor to print \"hello\".") +sleep(15) From 1db867126fc3387871fa191b200472c67a57efa8 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Tue, 14 Feb 2017 10:52:20 +0000 Subject: [PATCH 13/13] gpio: Add get_type function Signed-off-by: Francois Berder --- letmecreate/core/gpio.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/letmecreate/core/gpio.py b/letmecreate/core/gpio.py index dcc7f53..6c3fb98 100644 --- a/letmecreate/core/gpio.py +++ b/letmecreate/core/gpio.py @@ -71,6 +71,21 @@ def get_pin(mikrobus_index, pin_type): return pin.value +def get_type(gpio_pin): + """Returns the type of the GPIO + + Some GPIO's on the Mikrobus has some type (AN, PWM, INT, RST or CS). Other + GPIO's don't have a type. + + Note: An exception is thrown if the type of the gpio cannot be found. + """ + pin_type = ctypes.c_uint8(0) + ret = _LIB.gpio_get_type(gpio_pin, ctypes.byref(pin_type)) + if ret < 0: + raise Exception("gpio get type failed") + return pin_type.value + + def set_direction(gpio_pin, direction): """Configure GPIO as an input or an output.