diff options
author | Geoff Gustafson <geoff@linux.intel.com> | 2017-12-06 17:31:24 -0800 |
---|---|---|
committer | Geoff Gustafson <geoff@linux.intel.com> | 2017-12-15 12:54:35 -0800 |
commit | 817af2bcdbd23d6fe7152854fea71be1e5194af1 (patch) | |
tree | 6abf09dd83cb722a8c1dc11482024088c542e7a8 | |
parent | a84ea70d2028a8957abeaaf19cf47fcd9ad92b2b (diff) |
[aio] Use board pin mechanism for AIO; remove old pins modules
Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
-rw-r--r-- | Makefile.linux | 3 | ||||
-rw-r--r-- | samples/AIO.js | 15 | ||||
-rwxr-xr-x | scripts/trlite | 6 | ||||
-rw-r--r-- | src/zjs_a101_pins.c | 100 | ||||
-rw-r--r-- | src/zjs_aio.c | 220 | ||||
-rw-r--r-- | src/zjs_aio.json | 2 | ||||
-rw-r--r-- | src/zjs_aio_a101.c | 66 | ||||
-rw-r--r-- | src/zjs_arduino101_pins.json | 7 | ||||
-rw-r--r-- | src/zjs_ashell.json | 1 | ||||
-rw-r--r-- | src/zjs_board.c | 470 | ||||
-rw-r--r-- | src/zjs_common.h | 5 | ||||
-rw-r--r-- | src/zjs_frdm_k64f.json | 1 | ||||
-rw-r--r-- | src/zjs_gpio.c | 3 | ||||
-rw-r--r-- | src/zjs_k64f_pins.c | 93 | ||||
-rw-r--r-- | src/zjs_k64f_pins.json | 6 | ||||
-rw-r--r-- | zjs.conf | 1 |
16 files changed, 404 insertions, 595 deletions
diff --git a/Makefile.linux b/Makefile.linux index 561e9d8..882b1f7 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -11,8 +11,7 @@ BUILD_DIR = $(O)/$(VARIANT) UNAME := $(shell uname) -CORE_SRC += src/zjs_a101_pins.c \ - src/zjs_board.c \ +CORE_SRC += src/zjs_board.c \ src/zjs_buffer.c \ src/zjs_callbacks.c \ src/zjs_common.c \ diff --git a/samples/AIO.js b/samples/AIO.js index 126c215..0d3b6df 100644 --- a/samples/AIO.js +++ b/samples/AIO.js @@ -1,22 +1,15 @@ // Copyright (c) 2016-2017, Intel Corporation. // Sample code for showing how to to read raw input value from the analog -// pins on FRDM_K64f board or the Arduino 101, specifically A0 and A1 -// on the Arduino 101, which is mapped to pin 10 and pin 11 on Zephyr, -// where one is doing a synchronous read and the other does it asynchronously +// pins on FRDM_K64f board or the Arduino 101, specifically A0 and A1, +// where one is doing a synchronous read and the other does it asynchronously. // import aio module var aio = require("aio"); -var board = require("board"); -if (board.name === "arduino_101") { - var pins = require("arduino101_pins"); -} else { - var pins = require("k64f_pins"); -} // pins -var pinA = aio.open({ pin: pins.A0 }); -var pinB = aio.open({ pin: pins.A1 }); +var pinA = aio.open({ pin: 'A0' }); +var pinB = aio.open({ pin: 'A1' }); setInterval(function () { var rawValue = pinA.read(); diff --git a/scripts/trlite b/scripts/trlite index 292687c..34f5cea 100755 --- a/scripts/trlite +++ b/scripts/trlite @@ -292,8 +292,7 @@ if [ "$RUN" == "all" -o "$RUN" == "1" ]; then # A101 build tests spanning all modules try_command "hello world" make $VERBOSE - MODULES=(aio arduino101_pins ble dgram events gpio grove_lcd i2c \ - performance pwm uart) + MODULES=(aio ble dgram events gpio grove_lcd i2c performance pwm uart) SENSORS=(Accelerometer AmbientLightSensor Gyroscope Magnetometer TemperatureSensor) write_modules_test $TMPFILE $MODULES $SENSORS @@ -327,8 +326,7 @@ if [ "$RUN" == "all" -o "$RUN" == "2" ]; then # k64f build tests try_command "k64f hello" make $VERBOSE BOARD=frdm_k64f - MODULES=(ble board dgram events fs gpio grove_lcd i2c k64f_pins performance - pwm uart) + MODULES=(ble board dgram events fs gpio grove_lcd i2c performance pwm uart) SENSORS=(Accelerometer) write_modules_test $TMPFILE $MODULES $SENSORS diff --git a/src/zjs_a101_pins.c b/src/zjs_a101_pins.c deleted file mode 100644 index a63b633..0000000 --- a/src/zjs_a101_pins.c +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) 2016-2017, Intel Corporation. - -// ZJS includes -#include "zjs_common.h" -#include "zjs_pwm.h" -#include "zjs_util.h" - -#ifdef BUILD_MODULE_PWM -static void zjs_a101_num_to_pwm(u32_t num, int *dev, int *pin) -{ - *dev = 0; - if (num < 0) { - *pin = -1; - return; - } - if (num < 4) { - // support directly giving channel number 0-3 - *pin = num; - return; - } - if (num >= 0x20 && num <= 0x23) { - // support PWM0 through PWM3 - *pin = num - 0x20; - return; - } - - switch (num) { - case 17: // IO3 - *pin = 0; - break; - case 15: // IO5 - *pin = 1; - break; - case 12: // IO6 - *pin = 2; - break; - case 13: // IO9 - *pin = 3; - break; - - default: - *pin = -1; - } -} -#endif - -static jerry_value_t zjs_a101_init() -{ - // effects: returns an object with Arduino 101 pin mappings -#ifdef BUILD_MODULE_PWM - zjs_pwm_convert_pin = zjs_a101_num_to_pwm; -#endif - - jerry_value_t obj = zjs_create_object(); - - // These are all the GPIOs that can be accessed as GPIOs by the X86 side. - zjs_obj_add_number(obj, "IO2", 18); - zjs_obj_add_number(obj, "IO3", 17); // doesn't seem to work as output - zjs_obj_add_number(obj, "IO4", 19); - zjs_obj_add_number(obj, "IO5", 15); // doesn't seem to work as output - zjs_obj_add_number(obj, "IO7", 20); - zjs_obj_add_number(obj, "IO8", 16); - zjs_obj_add_number(obj, "IO10", 11); - zjs_obj_add_number(obj, "IO11", 10); - zjs_obj_add_number(obj, "IO12", 9); - zjs_obj_add_number(obj, "IO13", 8); // output also displayed on LED0 - - // These are onboard LEDs - zjs_obj_add_number(obj, "LED0", 26); // active low, red fault LED - zjs_obj_add_number(obj, "LED1", 12); // active low - // LED2 is unavailable when SPI is in use because that reconfigures pin - // IO13 which this is tied to. The filesystem uses SPI to talk to the - // flash chip, so when you use filesystem APIs or ashell (which always - // uses the filesystem) this LED will not work. - zjs_obj_add_number(obj, "LED2", 8); - - // These cannot currently be used as GPIOs because they are controlled by - // the ARC side and we don't have support for that. But they can be used as - // PWMs. - zjs_obj_add_number(obj, "IO6", 12); - zjs_obj_add_number(obj, "IO9", 13); - - zjs_obj_add_number(obj, "PWM0", 0x20); - zjs_obj_add_number(obj, "PWM1", 0x21); - zjs_obj_add_number(obj, "PWM2", 0x22); - zjs_obj_add_number(obj, "PWM3", 0x23); - - // TODO: It appears that some other GPIO pins can be used as analog inputs - // too, from the X86 side. We haven't tried that. - zjs_obj_add_number(obj, "A0", 10); - zjs_obj_add_number(obj, "A1", 11); - zjs_obj_add_number(obj, "A2", 12); - zjs_obj_add_number(obj, "A3", 13); - zjs_obj_add_number(obj, "A4", 14); - zjs_obj_add_number(obj, "A5", 9); - - return obj; -} - -JERRYX_NATIVE_MODULE(arduino101_pins, zjs_a101_init) diff --git a/src/zjs_aio.c b/src/zjs_aio.c index 766327e..82ba3bf 100644 --- a/src/zjs_aio.c +++ b/src/zjs_aio.c @@ -10,9 +10,10 @@ #include <misc/util.h> // ZJS includes +#include "zjs_board.h" #include "zjs_callbacks.h" -#include "zjs_event.h" #include "zjs_common.h" +#include "zjs_event.h" #include "zjs_modules.h" #include "zjs_util.h" @@ -20,18 +21,13 @@ const int MAX_TYPE_LEN = 20; -static struct device *adc_device[2] = { NULL, NULL }; // ADC_0 and ADC_1 -static u8_t pin_enabled[AIO_LEN] = {}; -static u32_t pin_values[AIO_LEN] = {}; -static u32_t pin_last_values[AIO_LEN] = {}; -static u8_t seq_buffer[ADC_BUFFER_SIZE]; -static u32_t last_read_time = 0; - -static jerry_value_t zjs_aio_prototype; +static jerry_value_t zjs_aio_prototype = 0; typedef struct aio_handle { + struct device *dev; jerry_value_t pin_obj; - u32_t pin; + u16_t pin; + u16_t last_value; struct aio_handle *next; } aio_handle_t; @@ -42,72 +38,20 @@ static aio_handle_t *opened_handles = NULL; aio_handle_t *var = (aio_handle_t *)zjs_event_get_user_handle(obj); \ if (!var) { return zjs_error("no aio handle"); } -static u8_t map_device(u8_t pin) -{ - if (pin == 12 || pin == 13) { - return 0; - } else if (pin == 14 || pin == 15) { - return 1; - } - - ERR_PRINT("invalid pin %d\n", pin); - return -1; -} - -static const char* map_device_name(u8_t pin) -{ - if (pin == 12 || pin == 13) { - return CONFIG_ADC_0_NAME; - } else if (pin == 14 || pin == 15) { - return CONFIG_ADC_1_NAME; - } - - ERR_PRINT("invalid pin %d\n", pin); - return NULL; -} - -static aio_handle_t *aio_alloc_handle() -{ - size_t size = sizeof(aio_handle_t); - aio_handle_t *handle = zjs_malloc(size); - if (handle) { - memset(handle, 0, size); - } - return handle; -} - static void aio_free_cb(void *ptr) { - aio_handle_t *handle = (aio_handle_t *)ptr; - u32_t pin = handle->pin; - pin_enabled[pin - AIO_MIN]--; - DBG_PRINT("AIO pin %d refcount %d\n", pin, pin_enabled[pin - AIO_MIN]); - - struct device *dev = adc_device[map_device(handle->pin)]; - if (dev) { - if (((pin == 12 || pin == 13) && - (pin_enabled[0] == 0 && pin_enabled[1] == 0)) || - ((pin == 14 || pin == 15) && - (pin_enabled[2] == 0 && pin_enabled[3] == 0))) { - // if no more A0 and A1 pins opened, disable ADC_0 - // if no more A2 and A3 pins opened, disable ADC_1 - DBG_PRINT("disabling ADC device\n"); - adc_disable(dev); - adc_device[map_device(handle->pin)] = NULL; - } - } - - jerry_release_value(handle->pin_obj); - // remove from the list of opened handles + aio_handle_t *handle = (aio_handle_t *)ptr; ZJS_LIST_REMOVE(aio_handle_t, opened_handles, handle); zjs_free(handle); } -static s32_t pin_read(u8_t pin) +static u16_t pin_read(struct device *dev, u8_t pin) { + u8_t seq_buffer[ADC_BUFFER_SIZE]; + struct adc_seq_entry entry = { - .sampling_delay = 30 , + .sampling_delay = 30, .channel_id = pin, .buffer = seq_buffer, .buffer_length = ADC_BUFFER_SIZE, @@ -118,38 +62,20 @@ static s32_t pin_read(u8_t pin) .num_entries = 1, }; - struct device *dev = adc_device[map_device(pin)]; - if (!dev) { - ERR_PRINT("ADC device not found with pin %d\n", pin); - return -1; - } - if (adc_read(dev, &entry_table) != 0) { ERR_PRINT("couldn't read from pin %d\n", pin); return -1; } // read from buffer, not sure if byte order is important - u32_t raw_value = (u32_t)seq_buffer[0] | (u32_t)seq_buffer[1] << 8; - - return raw_value; + return seq_buffer[0] | seq_buffer[1] << 8; } -static jerry_value_t aio_pin_read(const jerry_value_t function_obj, - const jerry_value_t this, - const jerry_value_t argv[], - const jerry_length_t argc, - bool async) +static ZJS_DECL_FUNC_ARGS(aio_pin_read, bool async) { - u32_t pin; - zjs_obj_get_uint32(this, "pin", &pin); - - if (pin < AIO_MIN || pin > AIO_MAX) { - DBG_PRINT("PIN: #%u\n", pin); - return zjs_error("pin out of range"); - } + GET_AIO_HANDLE(this, handle); - s32_t value = pin_read(pin); + u16_t value = pin_read(handle->dev, handle->pin); if (value < 0) { return ZJS_ERROR("AIO read failed"); } @@ -193,66 +119,57 @@ static ZJS_DECL_FUNC(zjs_aio_pin_read_async) static ZJS_DECL_FUNC(zjs_aio_pin_close) { - u32_t pin; - zjs_obj_get_uint32(this, "pin", &pin); GET_AIO_HANDLE(this, handle); - aio_free_cb(handle); - return ZJS_UNDEFINED; } static ZJS_DECL_FUNC(zjs_aio_open) { - // args: initialization object - ZJS_VALIDATE_ARGS(Z_OBJECT); + // args: initialization object or int/string pin number + ZJS_VALIDATE_ARGS(Z_NUMBER Z_STRING Z_OBJECT); - jerry_value_t data = argv[0]; + ZVAL_MUTABLE pin_str = 0; + jerry_value_t pin_val = argv[0]; + jerry_value_t init = 0; - u32_t pin; - if (!zjs_obj_get_uint32(data, "pin", &pin)) - return zjs_error("missing required field (pin)"); + if (jerry_value_is_object(argv[0])) { + init = argv[0]; + pin_str = zjs_get_property(init, "pin"); + pin_val = pin_str; + } - if (pin < AIO_MIN || pin > AIO_MAX) { - DBG_PRINT("PIN: #%u\n", pin); - return zjs_error("pin out of range"); + char devname[20]; + int pin = zjs_board_find_aio(pin_val, devname, 20); + if (pin == FIND_PIN_INVALID) { + return TYPE_ERROR("bad pin argument"); + } + else if (pin == FIND_DEVICE_FAILURE) { + return zjs_error("device not found"); + } + else if (pin < 0) { + return zjs_error("pin not found"); + } + struct device *aiodev = device_get_binding(devname); + if (!aiodev) { + return zjs_error("device not found"); } // create the AIOPin object jerry_value_t pinobj = zjs_create_object(); jerry_set_prototype(pinobj, zjs_aio_prototype); - zjs_obj_add_number(pinobj, "pin", pin); - aio_handle_t *handle = aio_alloc_handle(); + aio_handle_t *handle = zjs_malloc(sizeof(aio_handle_t)); if (!handle) { - return zjs_error("could not allocate handle"); + return zjs_error("out of memory"); } - - // lookup what device the pins are connected to - // A0 and A1 are connected to ADC_0, A2 and A3 are connected to ADC_1 - struct device *dev = adc_device[map_device(pin)]; - if (!dev) { - const char *dev_name = map_device_name(pin); - if (dev_name) { - dev = device_get_binding(dev_name); - if (!dev) { - zjs_free(handle); - return zjs_error("failed to initialize AIO device"); - } - adc_enable(dev); - adc_device[map_device(pin)] = dev; - } else { - zjs_free(handle); - return zjs_error("failed to find ADC device"); - } - } - - pin_enabled[pin - AIO_MIN]++; - DBG_PRINT("AIO pin %d refcount %d\n", pin, pin_enabled[pin-12]); - - handle->pin_obj = jerry_acquire_value(pinobj); + memset(handle, 0, sizeof(aio_handle_t)); + handle->dev = aiodev; handle->pin = pin; + // TODO: verify that not acquiring here is okay + handle->pin_obj = pinobj; + // make it an emitter object zjs_make_emitter(pinobj, zjs_aio_prototype, handle, aio_free_cb); @@ -263,35 +180,28 @@ static ZJS_DECL_FUNC(zjs_aio_open) static s32_t aio_poll_routine(void *h) { + static u32_t last_read_time = 0; u32_t uptime = k_uptime_get_32(); if ((uptime - last_read_time) > ((u32_t)(CONFIG_SYS_CLOCK_TICKS_PER_SEC / AIO_POLL_FREQUENCY * 10))) { - for (int i = 0; i < AIO_LEN; i++) { - if (pin_enabled[i]) { - // FIXME: We dont know when a object subscribes to onchange - // events, need a way to intercept the .on() - // currently, if the pin is opened, then it do a read - // and signal the event, this could slow down the system - // when there are multiple AIO pins opened. - pin_values[i] = pin_read(i + AIO_MIN); - last_read_time = uptime; - if (pin_values[i] != pin_last_values[i]) { - // send updates only if value has changed - aio_handle_t *h = ZJS_LIST_FIND(aio_handle_t, - opened_handles, pin, - i + AIO_MIN); - if (h) { - ZVAL val = jerry_create_number(pin_values[i]); - zjs_defer_emit_event(h->pin_obj, "change", - &val, - sizeof(val), - zjs_copy_arg, - zjs_release_args); - } - pin_last_values[i] = pin_values[i]; - } + aio_handle_t *handle = opened_handles; + while (handle) { + // FIXME: We dont know when a object subscribes to onchange + // events, need a way to intercept the .on() + // currently, if the pin is opened, then it do a read + // and signal the event, this could slow down the system + // when there are multiple AIO pins opened. + u16_t value = pin_read(handle->dev, handle->pin); + if (value != handle->last_value) { + handle->last_value = value; + ZVAL val = jerry_create_number(value); + zjs_defer_emit_event(handle->pin_obj, "change", &val, + sizeof(val), zjs_copy_arg, + zjs_release_args); } + handle = handle->next; } + last_read_time = uptime; } zjs_loop_unblock(); @@ -300,6 +210,10 @@ static s32_t aio_poll_routine(void *h) static void zjs_aio_cleanup(void *native) { + while (opened_handles) { + zjs_free(opened_handles); + opened_handles = opened_handles->next; + } jerry_release_value(zjs_aio_prototype); zjs_unregister_service_routine(aio_poll_routine); } diff --git a/src/zjs_aio.json b/src/zjs_aio.json index 6f16f1d..26b4f79 100644 --- a/src/zjs_aio.json +++ b/src/zjs_aio.json @@ -1,6 +1,6 @@ { "module": "aio", "require": "aio", - "depends": ["aio_a101", "aio_k64f", "events"], + "depends": ["aio_a101", "aio_k64f", "board", "events"], "targets": ["arduino_101", "frdm_k64f"] } diff --git a/src/zjs_aio_a101.c b/src/zjs_aio_a101.c index 0c455d0..0fb88d5 100644 --- a/src/zjs_aio_a101.c +++ b/src/zjs_aio_a101.c @@ -9,6 +9,7 @@ #include <misc/util.h> // ZJS includes +#include "zjs_board.h" #include "zjs_callbacks.h" #include "zjs_event.h" #include "zjs_ipm.h" @@ -73,16 +74,6 @@ static bool zjs_aio_ipm_send_sync(zjs_ipm_message_t *send, return true; } -static aio_handle_t *aio_alloc_handle() -{ - size_t size = sizeof(aio_handle_t); - aio_handle_t *handle = zjs_malloc(size); - if (handle) { - memset(handle, 0, size); - } - return handle; -} - static void aio_free_cb(void *ptr) { aio_handle_t *handle = (aio_handle_t *)ptr; @@ -170,18 +161,12 @@ static jerry_value_t aio_pin_read(const jerry_value_t function_obj, const jerry_length_t argc, bool async) { - u32_t pin; - zjs_obj_get_uint32(this, "pin", &pin); - - if (pin < AIO_MIN || pin > AIO_MAX) { - DBG_PRINT("PIN: #%u\n", pin); - return zjs_error("pin out of range"); - } + GET_AIO_HANDLE(this, handle); // send IPM message to the ARC side zjs_ipm_message_t send; send.type = TYPE_AIO_PIN_READ; - send.data.aio.pin = pin; + send.data.aio.pin = handle->pin; jerry_value_t result = zjs_aio_call_remote_function(&send); @@ -232,18 +217,29 @@ static ZJS_DECL_FUNC(zjs_aio_pin_close) static ZJS_DECL_FUNC(zjs_aio_open) { - // args: initialization object - ZJS_VALIDATE_ARGS(Z_OBJECT); + // args: initialization object or int/string pin number + ZJS_VALIDATE_ARGS(Z_NUMBER Z_STRING Z_OBJECT); - jerry_value_t data = argv[0]; + ZVAL_MUTABLE pin_str = 0; + jerry_value_t pin_val = argv[0]; + jerry_value_t init = 0; - u32_t pin; - if (!zjs_obj_get_uint32(data, "pin", &pin)) - return zjs_error("missing required field (pin)"); + if (jerry_value_is_object(argv[0])) { + init = argv[0]; + pin_str = zjs_get_property(init, "pin"); + pin_val = pin_str; + } - if (pin < AIO_MIN || pin > AIO_MAX) { - DBG_PRINT("PIN: #%u\n", pin); - return zjs_error("pin out of range"); + char devname[20]; + int pin = zjs_board_find_aio(pin_val, devname, 20); + if (pin == FIND_PIN_INVALID) { + return TYPE_ERROR("bad pin argument"); + } + else if (pin == FIND_DEVICE_FAILURE) { + return zjs_error("device not found"); + } + else if (pin < 0) { + return zjs_error("pin not found"); } // send IPM message to the ARC side @@ -251,25 +247,25 @@ static ZJS_DECL_FUNC(zjs_aio_open) send.type = TYPE_AIO_OPEN; send.data.aio.pin = pin; - jerry_value_t result = zjs_aio_call_remote_function(&send); + ZVAL result = zjs_aio_call_remote_function(&send); if (jerry_value_has_error_flag(result)) return result; - jerry_release_value(result); // create the AIOPin object jerry_value_t pinobj = zjs_create_object(); jerry_set_prototype(pinobj, zjs_aio_prototype); - zjs_obj_add_number(pinobj, "pin", pin); - aio_handle_t *handle = aio_alloc_handle(); + aio_handle_t *handle = zjs_malloc(sizeof(aio_handle_t)); if (!handle) { - return zjs_error("could not allocate handle"); + return zjs_error("out of memory"); } - - handle->pin_obj = jerry_acquire_value(pinobj); + memset(handle, 0, sizeof(aio_handle_t)); handle->pin = pin; - // make it an emitter object and subscribe to changes + // TODO: verify that not acquiring here is okay + handle->pin_obj = pinobj; + + // make it an emitter object zjs_make_emitter(pinobj, zjs_aio_prototype, handle, aio_free_cb); zjs_aio_ipm_send_async(TYPE_AIO_PIN_SUBSCRIBE, pin, handle); diff --git a/src/zjs_arduino101_pins.json b/src/zjs_arduino101_pins.json deleted file mode 100644 index 0e26e0e..0000000 --- a/src/zjs_arduino101_pins.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "module": "arduino101_pins", - "require": "arduino101_pins", - "targets": ["arduino_101"], - "zjs_config": ["-DBUILD_MODULE_A101"], - "src": ["src/zjs_a101_pins.c"] -} diff --git a/src/zjs_ashell.json b/src/zjs_ashell.json index dc527a6..aed27f4 100644 --- a/src/zjs_ashell.json +++ b/src/zjs_ashell.json @@ -2,7 +2,6 @@ "module": "ashell", "depends": [ "aio", - "arduino101_pins", "ble", "common", "console", diff --git a/src/zjs_board.c b/src/zjs_board.c index 1ba0624..6e09261 100644 --- a/src/zjs_board.c +++ b/src/zjs_board.c @@ -24,6 +24,15 @@ typedef struct { #endif } pin_map_t; +// E.g. to map IO3-5 to pin entries 7-9, use: +// prefix "IO", offset 3, start 7, end 9 +typedef struct { + const char *prefix; + pin_id_t offset; + pin_id_t start; + pin_id_t end; +} prefix_range_t; + typedef struct { pin_id_t start; pin_id_t end; @@ -46,68 +55,97 @@ typedef struct { // Arduino 101 board support // +#ifdef BUILD_MODULE_GPIO +// prefix before GPIO device id +static const char *digital_prefix = "GPIO_"; + +// map gpio_ports integers to device id characters +static const char *digital_convert = "0"; + // data from zephyr/boards/x86/arduino_101/pinmux.c -// *dual pins mean there's another zephyr pin that maps to the same user pin, -// exposing distinct functionality; unclear how to understand this so far -static const pin_map_t pin_data[] = { - {0, 255, 9}, // IO0 - {0, 255, 8}, // IO1 - {0, 18, 255}, // IO2 - {0, 17, 10}, // IO3 - {0, 19, 255}, // IO4 - {0, 15, 11}, // IO5 - {0, 255, 12}, // IO6 - {0, 20, 255}, // IO7 - {0, 16, 255}, // IO8 - {0, 255, 13}, // IO9 - {0, 11, 0}, // IO10 - {0, 10, 3}, // IO11 - {0, 9, 1}, // IO12 - {0, 8, 2}, // IO13 - {0, 26, 255}, // LED0 - {0, 12, 255}, // LED1 - {0, 8, 2}, // LED2 (aka IO13) - {0, 255, 10}, // AD0 - {0, 255, 11}, // AD1 - {0, 255, 12}, // AD2 - {0, 255, 13}, // AD3 - {0, 255, 14}, // AD4 - {0, 255, 9}, // AD5 - {0, 0, 255}, // PWM0 (aka IO3) - {0, 1, 255}, // PWM1 (aka IO5) - {0, 2, 255}, // PWM2 (aka IO6) - {0, 3, 255} // PWM3 (aka IO9) +static const pin_map_t digital_pins[] = { + {0, 255}, // IO0 + {0, 255}, // IO1 + {0, 18}, // IO2 + {0, 17}, // IO3 + {0, 19}, // IO4 + {0, 15}, // IO5 + {0, 255}, // IO6 + {0, 20}, // IO7 + {0, 16}, // IO8 + {0, 255}, // IO9 + {0, 11}, // IO10 + {0, 10}, // IO11 + {0, 9}, // IO12 + {0, 8}, // IO13 + {0, 26}, // LED0 + {0, 12}, // LED1 + {0, 8}, // LED2 (aka IO13) }; -static const pin_range_t digital_pins = {0, 13}; -#ifdef BUILD_MODULE_GPIO -static const pin_range_t led_pins = {14, 16}; -#endif +static const prefix_range_t digital_map[] = { + {"IO", 0, 0, 13}, // IO0 - IO13 + {"LED", 0, 14, 16} // LED0 - LED2 +}; + +static const extra_pin_t digital_extras[] = {}; +#endif // BUILD_MODULE_GPIO + #ifdef BUILD_MODULE_AIO -static const pin_range_t analog_pins = {17, 22}; -#endif -static const extra_pin_t extra_pins[] = {}; +static const char *analog_prefix = "ADC_"; +static const char *analog_convert = "0"; +static const pin_map_t analog_pins[] = { + {0, 10}, // AD0 (pin numbers are for ARC side where these are used) + {0, 11}, // AD1 + {0, 12}, // AD2 + {0, 13}, // AD3 + {0, 14}, // AD4 + {0, 9}, // AD5 +}; +static const prefix_range_t analog_map[] = { + {"AD", 0, 0, 5}, // AD0 - AD5 + {"A", 0, 0, 5} // A0 - A5 +}; +static const extra_pin_t analog_extras[] = {}; +#endif // BUILD_MODULE_AIO #ifdef BUILD_MODULE_PWM -static const pin_range_t pwm_pins = {23, 26}; -static const pin_remap_t pwm_map[] = { // maps normal pins to PWM pins - {3, 23}, - {5, 24}, - {6, 25}, - {9, 26} +static const char *pwm_prefix = "PWM_"; +static const char *pwm_convert = "0"; +static const pin_map_t pwm_pins[] = { + {0, 0}, // PWM0 = IO3 + {0, 1}, // PWM1 = IO5 + {0, 2}, // PWM2 = IO6 + {0, 3} // PWM3 = IO9 }; -#endif +static const prefix_range_t pwm_map[] = { + {"PWM", 0, 0, 3} +}; +static const extra_pin_t pwm_extras[] = { + {"IO3", 0}, + {"IO5", 1}, + {"IO6", 2}, + {"IO9", 3} +}; +#endif // BUILD_MODULE_PWM #elif CONFIG_BOARD_FRDM_K64F // // FRDM-K64F board support // +#ifdef BUILD_MODULE_GPIO enum gpio_ports { PTA, PTB, PTC, PTD, PTE }; -static const pin_map_t pin_data[] = { +// prefix before GPIO device id +static const char *digital_prefix = "GPIO_"; + +// map gpio_ports integers to device id characters +static const char *digital_convert = "01234"; + +static const pin_map_t digital_pins[] = { {PTC, 16}, // D0 {PTC, 17}, // D1 {PTB, 9}, // D2 @@ -125,62 +163,104 @@ static const pin_map_t pin_data[] = { {PTD, 1}, // D13 {PTE, 25}, // D14 {PTE, 24}, // D15 - {PTB, 22}, // LEDR - {PTE, 26}, // LEDG - {PTB, 21}, // LEDB + {PTB, 22}, // LED0 (LEDR) + {PTE, 26}, // LED1 (LEDG) + {PTB, 21}, // LED2 (LEDB) {PTC, 6}, // SW2 {PTA, 4}, // SW3 - {PTB, 2}, // A0 - {PTB, 3}, // A1 - {PTB, 10}, // A2 - {PTB, 11}, // A3 - {PTC, 11}, // A4 - {PTC, 10}, // A5 - {PTA, 1}, // PWM0 - {PTA, 2}, // PWM1 - {PTC, 2}, // PWM2 - {PTC, 3}, // PWM3 - {PTC, 12}, // PWM4 - {PTC, 4}, // PWM5 - {PTD, 0}, // PWM6 - {PTD, 2}, // PWM7 - {PTD, 3}, // PWM8 - {PTD, 1} // PWM9 - // TODO: More pins at https://developer.mbed.org/platforms/FRDM-K64F/ }; -static const pin_range_t digital_pins = {0, 15}; -#ifdef BUILD_MODULE_GPIO -static const pin_range_t led_pins = {16, 18}; -#endif -#ifdef BUILD_MODULE_AIO -static const pin_range_t analog_pins = {21, 26}; -#endif -static const extra_pin_t extra_pins[] = { -#ifdef BUILD_MODULE_GPIO +static const prefix_range_t digital_map[] = { + {"D", 0, 0, 15}, // D0 - D15 + {"LED", 0, 16, 18}, // LED0 - LED2 + {"SW", 2, 19, 20} // SW2 - SW3 +}; + +// special named pins that aren't assigned by integer mapping +static const extra_pin_t digital_extras[] = { {"LEDR", 16}, {"LEDG", 17}, {"LEDB", 18}, - { "SW2", 19}, - { "SW3", 20} -#endif +}; +#endif // BUILD_MODULE_GPIO + +#ifdef BUILD_MODULE_AIO +enum aio_ports { + ADC0, ADC1 }; +// prefix before GPIO device id +static const char *analog_prefix = "ADC_"; + +// map gpio_ports integers to device id characters +static const char *analog_convert = "01"; + +// Documentation of pin mappings on the K64F board: +// https://os.mbed.com/platforms/FRDM-K64F/ +// Page 2 of schematic correlates pin names to ADC controller/channel: +// https://www.nxp.com/downloads/en/schematics/FRDM-K64F-SCH-C.pdf +static const pin_map_t analog_pins[] = { + {ADC0, 12}, // A0 = PTB2 + {ADC0, 13}, // A1 = PTB3 + {ADC1, 14}, // A2 = PTB10 + {ADC1, 15}, // A3 = PTB11 + // A4 = PTC11 + // A5 = PTC10 + {ADC1, 18}, // A6 (ZJS shortcut) is labeled ADC1_SE18 + {ADC0, 23}, // A7 (ZJS shortcut) is labeled DAC0_OUT +}; +// A4 and A5 are hardware triggered (denoted by the B in ADC1_SE7B), not +// supported by Zephyr currently +// The SoC has other analog inputs but they don't seem to be wired up +// on the K64F board; also some others are differential inputs that +// Zephyr doesn't support currently (e.g. ADC0_DM0/DP0) + +static const prefix_range_t analog_map[] = { + {"A", 0, 0, 3}, // A0 - A3 + {"A", 6, 4, 5} // A6 - A7 +}; + +static const extra_pin_t analog_extras[] = {}; +#endif // BUILD_MODULE_AIO + #ifdef BUILD_MODULE_PWM -static const pin_range_t pwm_pins = {27, 36}; -static const pin_remap_t pwm_map[] = { - { 3, 27}, - { 5, 28}, - { 6, 29}, - { 7, 30}, - { 8, 31}, - { 9, 32}, - {10, 33}, - {11, 34}, - {12, 35}, - {13, 36} +enum pwm_ports { + FTM0, FTM1, FTM2, FTM3 }; -#endif + +// prefix before PWM device id +static const char *pwm_prefix = "PWM_"; + +// map pwm_ports integers to device id characters +static const char *pwm_convert = "0123"; + +static const pin_map_t pwm_pins[] = { + // names PWM0-11 are ZJS-only shortcuts not found in K64F docs + {FTM0, 6}, // PWM0 = PTA1 = D3 + {FTM0, 7}, // PWM1 = PTA2 = D5 + {FTM0, 1}, // PWM2 = PTC2 = D6 + {FTM0, 2}, // PWM3 = PTC3 = D7 + // PWM4 = PTC12 = D8 (not sure what FTM3_FLT0 means) + {FTM0, 3}, // PWM5 = PTC4 = D9 + {FTM3, 0}, // PWM6 = PTD0 = D10 + {FTM3, 2}, // PWM7 = PTD2 = D11 + {FTM3, 3}, // PWM8 = PTD3 = D12 + {FTM3, 1}, // PWM9 = PTD1 = D13 + {FTM3, 7}, // PWM10 = PTC11 = A4 + {FTM3, 6}, // PWM11 = PTC10 = A5 +}; + +static const prefix_range_t pwm_map[] = { + {"PWM", 0, 0, 3}, // PWM0 - PWM3 + {"PWM", 5, 4, 10}, // PWM5 - PWM11 + {"D", 3, 0, 0}, // D3 + {"D", 5, 1, 3}, // D5 - D7 + {"D", 9, 4, 8} // D9 - D13 + {"A", 4, 9, 10} // A4 - A5 +}; + +static const extra_pin_t pwm_extras[] = {}; +#endif // BUILD_MODULE_PWM #else // @@ -196,46 +276,22 @@ typedef struct { const pin_range_t *range; } prefix_t; -#ifndef BASIC_BOARD_SUPPORT -static const prefix_t prefix_map[] = { - { "IO", &digital_pins}, - { "D", &digital_pins}, -#ifdef BUILD_MODULE_GPIO - {"LED", &led_pins}, -#endif -#ifdef BUILD_MODULE_AIO - { "AD", &analog_pins}, - { "A", &analog_pins}, -#endif -#ifdef BUILD_MODULE_PWM - {"PWM", &pwm_pins} -#endif -}; - -static int find_named_pin(const char *name, const pin_range_t *default_range, - char *device_prefix, const pin_remap_t *remap, - int remap_len, char *device_name, int name_len) +static int split_pin_name(const char *name, char *prefix, int *number) { - // requires: name is a pin name from JavaScript; default_range specifies the - // start and end values if name is a numeric pin; device_prefix - // is the prefix string e.g. GPIO for GPIO_0 device; remap is - // an array of pin numbers that should be remapped if found, or - // NULL; remap_len is the length of that array, and device_name - // is a place to store the device driver name, name_len is the - // receiving buffer length - // effects: searches for a pin name matching name, which may have an alpha - // prefix and may have a numeric suffix, but at least one of the - // two; if the name is numeric only, uses default_range to - // validate the pin, otherwise one based on the prefix; when the - // pin is found, remaps it to another pin if remap is specified; - // finally returns the right device name in device-name, and - // returns the correct Zephyr pin + // requires: name is a pin name from JavaScript; prefix is a buffer with + // at least NAMED_PIN_MAX_LEN bytes; number is a pointer to + // an int to receive numeric portion of pin name + // effects: if name is NAMED_PIN_MAX_LEN or longer, returns a + // FIND_PIN_INVALID; if name contains characters following + // digits, returns FIND_PIN_INVALID; otherwise, if there are + // no digits, copies name to prefix and sets number to -1; if + // there are digits, copies any alphabet prefix in name to + // prefix, then parses the numeric value into number; on + // success, returns 0 ZJS_ASSERT(name, "name is NULL"); - ZJS_ASSERT(default_range, "default_range is NULL"); - ZJS_ASSERT(device_prefix, "device_prefix is NULL"); if (strnlen(name, NAMED_PIN_MAX_LEN) == NAMED_PIN_MAX_LEN) { - DBG_PRINT("pin name too long\n"); + DBG_PRINT("pin name too long: '%s'\n", name); return FIND_PIN_INVALID; } @@ -248,83 +304,140 @@ static int find_named_pin(const char *name, const pin_range_t *default_range, } } - int id = -1; - + long num = -1; if (index != -1) { // at least one digit was found - const pin_range_t *range = NULL; - if (!index) { - // no prefix found; treat raw number as a default range - range = default_range; - } - else { - // prefix found, find match to determine range - char prefix[index + 1]; - strncpy(prefix, name, index); - prefix[index] = '\0'; - int len = sizeof(prefix_map) / sizeof(prefix_t); - for (int i = 0; i < len; ++i) { - if (strequal(prefix, prefix_map[i].prefix)) { - range = prefix_map[i].range; - break; - } - } + char *end; + num = strtol(name + index, &end, 10); + if (*end) { + DBG_PRINT("invalid pin suffix: '%s'\n", end); + return FIND_PIN_INVALID; } + } - if (range) { - char *end; - long num = strtol(name + index, &end, 10) + range->start; - if (*end) { - return FIND_PIN_INVALID; - } + strncpy(prefix, name, index); + prefix[index] = '\0'; + *number = num; + return 0; +} + +static int find_pin_id(const char *name, + const prefix_range_t map[], int map_len, + const extra_pin_t extra[], int extra_len) +{ + // requires: name is a pin name from JavaScript; map is an array of + // prefixes with range and offset that map to pins; map_len is + // the number of entries in map; extra is an array of special + // pin numbers and pin ids; extra_len is the number of entries + // in extra + // effects: searches for a pin name matching name, which may have an alpha + // prefix and may have a numeric suffix, but at least one of the + // two; if the name is numeric only, uses the first prefix in + // map to validate the pin, otherwise one based on the prefix; + // returns the id (row) in map that matches, or <0 on error + + char prefix[NAMED_PIN_MAX_LEN]; + int number; + int rval = split_pin_name(name, prefix, &number); + if (rval < 0) { + return rval; + } - if (num >= range->start && num <= range->end) { - id = num; + int id = -1; + if (number != -1 && map_len > 0) { + // at least one digit was found + if (prefix[0] == '\0') { + // no prefix found; use default from first entry + strcpy(prefix, map[0].prefix); + } + + // prefix found, find match to determine range + for (int i = 0; i < map_len; ++i) { + if (strequal(prefix, map[i].prefix)) { + // if number in range, use it + int num = number - map[i].offset + map[i].start; + if (num <= map[i].end) { + id = num; + break; + } } } } if (id < 0) { // still not found, try extras - int len = sizeof(extra_pins) / sizeof(extra_pin_t); - for (int i = 0; i < len; ++i) { - if (strequal(name, extra_pins[i].name)) { - id = extra_pins[i].id; + for (int i = 0; i < extra_len; ++i) { + if (strequal(name, extra[i].name)) { + id = extra[i].id; } } } if (id < 0) { + DBG_PRINT("pin not found: '%s'\n", name); return FIND_PIN_FAILURE; } - // remap the pin if needed - for (int i = 0; i < remap_len; ++i) { - if (remap[i].from == id) { - id = remap[i].to; - break; - } + return id; +} + +// do not call this directly, use the macro below +static int find_named_pin_priv(const char *name, + const pin_map_t *pins, size_t pins_size, + const prefix_range_t *map, size_t map_size, + const extra_pin_t *extras, int extras_size, + const char *prefix, const char *convert, + char *device_name, int name_len) +{ + // requires: name is a pin name from JavaScript; pins is an array mapping + // pin id to device id / number; pins_size is the size in bytes + // of the array; extras is an array of other friendly pin names + // and the id in pins they correspond to; extras_size is the + // size in bytes of the array; prefix is the prefix to the + // device name, e.g. GPIO_ for GPIO_0 device; convert is a + // string mapping device ids to the character that follows the + // prefix for a specific device driver; device_name is a place + // to store the device driver name, name_len is the receiving + // buffer length + // effects: searches for a pin name matching name, which may have an alpha + // prefix and may have a numeric suffix, but at least one of the + // two; if the name is numeric only, uses the first prefix that + // occurs in map to validate the pin, otherwise one based on the + // prefix; when the pin is found, returns the right device name + // in device-name, and returns the correct Zephyr pin + int map_len = map_size / sizeof(prefix_range_t); + int extra_len = extras_size / sizeof(extra_pin_t); + int id = find_pin_id(name, map, map_len, extras, extra_len); + if (id < 0) { + return id; } - ZJS_ASSERT(id < sizeof(pin_data) / sizeof(pin_map_t), "pin id overflow"); + ZJS_ASSERT(id < pins_size / sizeof(pin_map_t), "pin id overflow"); - if (pin_data[id].zpin == 255) { + if (pins[id].zpin == 255) { // mode not supported DBG_PRINT("unsupported mode for id %d\n", id); return FIND_PIN_FAILURE; } // pin found, return results - int written = snprintf(device_name, name_len, "%s_%d", device_prefix, - pin_data[id].device); + int written = snprintf(device_name, name_len, "%s%d", prefix, + pins[id].device); if (written >= name_len) { DBG_PRINT("couldn't find device '%s'\n", name); return FIND_DEVICE_FAILURE; } - return pin_data[id].zpin; + DBG_PRINT("returning a pin %d, %d\n", id, pins[id].zpin); + return pins[id].zpin; } -#endif // !BASIC_BOARD_SUPPORT + +// call this instead of the above function, see above for arg descriptions +#define find_named_pin(name, pins, map, extras, prefix, convert, \ + device_name, name_len) \ + find_named_pin_priv(name, pins, sizeof(pins), map, sizeof(map), \ + extras, sizeof(extras), prefix, convert, \ + device_name, name_len) static int find_full_pin(const char *name, const char *pin, char *device_name, int name_len) @@ -397,6 +510,7 @@ static int find_pin(jerry_value_t jspin, char *pin_name, return find_full_pin(pin_name, ptr + 1, device_name, name_len); } + DBG_PRINT("pin '%s' is not a full pin\n", pin_name); return FIND_PIN_FAILURE; } #endif // BUILD_MODULE_GPIO || BUILD_MODULE_PWM || BUILD_MODULE_AIO @@ -409,10 +523,13 @@ int zjs_board_find_gpio(jerry_value_t jspin, char *device_name, int len) #ifndef BASIC_BOARD_SUPPORT if (pin == FIND_PIN_FAILURE) { - pin = find_named_pin(name, &digital_pins, "GPIO", NULL, 0, - device_name, len); + return find_named_pin(name, digital_pins, digital_map, digital_extras, + digital_prefix, digital_convert, + device_name, len); } + #endif + DBG_PRINT("gpio device name: '%s'\n", device_name); return pin; } #endif @@ -425,10 +542,11 @@ int zjs_board_find_aio(jerry_value_t jspin, char *device_name, int len) #ifndef BASIC_BOARD_SUPPORT if (pin == FIND_PIN_FAILURE) { - pin = find_named_pin(name, &analog_pins, "AIO", NULL, 0, - device_name, len); + pin = find_named_pin(name, analog_pins, analog_map, analog_extras, + analog_prefix, analog_convert, device_name, len); } #endif + DBG_PRINT("Returning pin %s:%d\n", device_name, pin); return pin; } #endif @@ -441,11 +559,11 @@ int zjs_board_find_pwm(jerry_value_t jspin, char *device_name, int len) #ifndef BASIC_BOARD_SUPPORT if (pin == FIND_PIN_FAILURE) { - int remap_len = sizeof(pwm_map) / sizeof(pin_remap_t); - pin = find_named_pin(name, &pwm_pins, "PWM", pwm_map, remap_len, - device_name, len); + pin = find_named_pin(name, pwm_pins, pwm_map, pwm_extras, + pwm_prefix, pwm_convert, device_name, len); } #endif + DBG_PRINT("pwm device name: '%s'\n", device_name); return pin; } #endif diff --git a/src/zjs_common.h b/src/zjs_common.h index 1f611ed..e3be6bb 100644 --- a/src/zjs_common.h +++ b/src/zjs_common.h @@ -130,7 +130,7 @@ int zjs_get_ms(void); // this is arbitrary but okay for now; added to avoid plain strlen below #define MAX_SCRIPT_SIZE 8192 -// board-specifc +// board-specific #if defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) #define ADC_DEVICE_NAME "ADC_0" #define ADC_BUFFER_SIZE 2 @@ -147,9 +147,6 @@ int zjs_get_ms(void); #define TEMP_DEVICE_NAME BMI160_NAME #elif CONFIG_BOARD_FRDM_K64F #define ADC_BUFFER_SIZE 5 -#define AIO_MIN 12 -#define AIO_MAX 15 -#define AIO_LEN 4 #define ACCEL_DEVICE_NAME CONFIG_FXOS8700_NAME #define MAGN_DEVICE_NAME CONFIG_FXOS8700_NAME #endif diff --git a/src/zjs_frdm_k64f.json b/src/zjs_frdm_k64f.json index 1ab274a..62d92ce 100644 --- a/src/zjs_frdm_k64f.json +++ b/src/zjs_frdm_k64f.json @@ -1,6 +1,5 @@ { "module":"frdm_k64f", - "depends": ["k64f_pins"], "targets": ["frdm_k64f"], "src": ["src/zjs_pinmux.c"], "zephyr_conf": { diff --git a/src/zjs_gpio.c b/src/zjs_gpio.c index f7bc461..58f9c3c 100644 --- a/src/zjs_gpio.c +++ b/src/zjs_gpio.c @@ -304,6 +304,9 @@ static ZJS_DECL_FUNC(zjs_gpio_open) jerry_set_prototype(pin_obj, gpio_pin_prototype); gpio_handle_t *handle = zjs_malloc(sizeof(gpio_handle_t)); + if (!handle) { + return zjs_error("out of memory"); + } memset(handle, 0, sizeof(gpio_handle_t)); handle->pin = pin; // FIXME: this seems wrong, it can probably never be freed diff --git a/src/zjs_k64f_pins.c b/src/zjs_k64f_pins.c deleted file mode 100644 index 5e32bca..0000000 --- a/src/zjs_k64f_pins.c +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 2016-2017, Intel Corporation. - -// Zephyr includes -#include <zephyr.h> - -// ZJS includes -#include "zjs_pwm.h" -#include "zjs_util.h" - -#ifdef BUILD_MODULE_PWM -static void zjs_k64f_num_to_pwm(u32_t num, int *dev, int *pin) -{ - int devnum = (num & 0xe0) >> 5; - if (devnum > 3) { - DBG_PRINT("Warning: invalid PWM device number\n"); - devnum = 0; - } - - // TODO: IMPLEMENT ME! - zjs_default_convert_pin(num, dev, pin); -} -#endif - -static jerry_value_t zjs_k64f_init() -{ - // effects: returns an object with FRDM-K64F pin mappings -#ifdef BUILD_MODULE_PWM - zjs_pwm_convert_pin = zjs_k64f_num_to_pwm; -#endif - - jerry_value_t obj = zjs_create_object(); - - const int PTA = 0x00; - const int PTB = 0x20; - const int PTC = 0x40; - const int PTD = 0x60; - const int PTE = 0x80; - - // These are all the Arduino GPIOs - zjs_obj_add_number(obj, "D0", PTC + 16); // verified I/O - zjs_obj_add_number(obj, "D1", PTC + 17); // verified I/O - zjs_obj_add_number(obj, "D2", PTB + 9); // verified I/O - zjs_obj_add_number(obj, "D3", PTA + 1); // verified I/O - zjs_obj_add_number(obj, "D4", PTB + 23); // verified I/O - zjs_obj_add_number(obj, "D5", PTA + 2); // verified I/O - zjs_obj_add_number(obj, "D6", PTC + 2); // verified I/O - zjs_obj_add_number(obj, "D7", PTC + 3); // verified I/O - - // currently not working on rev E3; used to work as input/output - zjs_obj_add_number(obj, "D8", PTC + 12); // PTA0 for Rev <= D - - zjs_obj_add_number(obj, "D9", PTC + 4); // verified I/O - zjs_obj_add_number(obj, "D10", PTD + 0); // verified I/O - zjs_obj_add_number(obj, "D11", PTD + 2); // verified I/O - zjs_obj_add_number(obj, "D12", PTD + 3); // verified I/O - zjs_obj_add_number(obj, "D13", PTD + 1); // verified I/O - zjs_obj_add_number(obj, "D14", PTE + 25); // verified I/O - zjs_obj_add_number(obj, "D15", PTE + 24); // verified I/O - - // These are for onboard RGB LED - zjs_obj_add_number(obj, "LEDR", PTB + 22); // verified - zjs_obj_add_number(obj, "LEDG", PTE + 26); // verified - zjs_obj_add_number(obj, "LEDB", PTB + 21); // verified - - // These are onboard switches SW2 and SW3 (SW1 is Reset) - zjs_obj_add_number(obj, "SW2", PTC + 6); // verified (press: falling edge) - zjs_obj_add_number(obj, "SW3", PTA + 4); - - // TODO: More pins at https://developer.mbed.org/platforms/FRDM-K64F/ - - // PWM pins - zjs_obj_add_number(obj, "PWM0", PTA + 1); - zjs_obj_add_number(obj, "PWM1", PTA + 2); - zjs_obj_add_number(obj, "PWM2", PTC + 2); - zjs_obj_add_number(obj, "PWM3", PTC + 3); - zjs_obj_add_number(obj, "PWM4", PTC + 12); - zjs_obj_add_number(obj, "PWM5", PTC + 4); - zjs_obj_add_number(obj, "PWM6", PTD + 0); - zjs_obj_add_number(obj, "PWM7", PTD + 2); - zjs_obj_add_number(obj, "PWM8", PTD + 3); - zjs_obj_add_number(obj, "PWM9", PTD + 1); - - // TODO: It appears that currently Zephyr only enables - // PTB2, PTB3, PTB10, PTB11, which are A0-A3 only, A4-A5 are not supported. - zjs_obj_add_number(obj, "A0", 12); - zjs_obj_add_number(obj, "A1", 13); - zjs_obj_add_number(obj, "A2", 14); - zjs_obj_add_number(obj, "A3", 15); - - return obj; -} - -JERRYX_NATIVE_MODULE(k64f_pins, zjs_k64f_init) diff --git a/src/zjs_k64f_pins.json b/src/zjs_k64f_pins.json deleted file mode 100644 index 48581c5..0000000 --- a/src/zjs_k64f_pins.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "module": "k64f_pins", - "require": "k64f_pins", - "zjs_config": ["-DBUILD_MODULE_K64F"], - "src": ["src/zjs_k64f_pins.c"] -} @@ -4,7 +4,6 @@ # Then pass CONFIG=zjs.conf to your make command. #ZJS_AIO=y -#ZJS_ARDUINO101_PINS=y #ZJS_BLE=y #ZJS_BUFFER=y #ZJS_CONSOLE=y |