1 /* 2 * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha (at) intel.com> 3 * Copyright (c) 2014 Intel Corporation. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sublicense, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be 14 * included in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25 #include <unistd.h> 26 #include <stdlib.h> 27 #include <stdint.h> 28 29 #include "nrf8001.h" 30 31 /** 32 * Include the services_lock.h to put the setup in the OTP memory of the nRF8001. 33 * This would mean that the setup cannot be changed once put in. 34 * However this removes the need to do the setup of the nRF8001 on every reset. 35 */ 36 37 void 38 init_local_interfaces (aci_state_t* aci, uint8_t reqn, uint8_t rdyn, uint8_t rst) { 39 /** 40 * Tell the ACI library, the MCU to nRF8001 pin connections. 41 * The Active pin is optional and can be marked UNUSED 42 */ 43 aci->aci_pins.board_name = BOARD_DEFAULT; // See board.h for details REDBEARLAB_SHIELD_V1_1 or BOARD_DEFAULT 44 aci->aci_pins.reqn_pin = reqn; // SS for Nordic board, 9 for REDBEARLAB_SHIELD_V1_1 45 aci->aci_pins.rdyn_pin = rdyn; // 3 for Nordic board, 8 for REDBEARLAB_SHIELD_V1_1 46 47 aci->aci_pins.reset_pin = rst; // 4 for Nordic board, UNUSED for REDBEARLAB_SHIELD_V1_1 48 aci->aci_pins.active_pin = UNUSED; 49 aci->aci_pins.optional_chip_sel_pin = UNUSED; 50 51 aci->aci_pins.interface_is_interrupt = false; // Interrupts still not available in Chipkit 52 aci->aci_pins.interrupt_number = 1; 53 54 lib_aci_init (aci, false); 55 } 56 57 void 58 close_local_interfaces (aci_state_t* aci) { 59 mraa_result_t error = MRAA_SUCCESS; 60 61 error = mraa_spi_stop(aci->aci_pins.m_spi); 62 if (error != MRAA_SUCCESS) { 63 64 } 65 error = mraa_gpio_close (aci->aci_pins.m_rdy_ctx); 66 if (error != MRAA_SUCCESS) { 67 68 } 69 error = mraa_gpio_close (aci->aci_pins.m_req_ctx); 70 if (error != MRAA_SUCCESS) { 71 72 } 73 error = mraa_gpio_close (aci->aci_pins.m_rst_ctx); 74 if (error != MRAA_SUCCESS) { 75 76 } 77 } 78