Skip to content

Commit 5c40b32

Browse files
authored
Merge pull request #58 from sandeepmistry/setPins
Add setPins API to override default WINC1500 pins
2 parents 51e76c8 + fd25ccd commit 5c40b32

File tree

7 files changed

+112
-37
lines changed

7 files changed

+112
-37
lines changed

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Server KEYWORD1
1515
# Methods and Functions (KEYWORD2)
1616
#######################################
1717

18+
setPins KEYWORD2
1819
status KEYWORD2
1920
connect KEYWORD2
2021
connectSSL KEYWORD2

src/WiFi.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
extern "C" {
2323
#include "bsp/include/nm_bsp.h"
24+
#include "bsp/include/nm_bsp_arduino.h"
2425
#include "socket/include/socket_buffer.h"
2526
#include "socket/include/m2m_socket_host_if.h"
2627
#include "driver/source/nmasic.h"
@@ -174,6 +175,14 @@ WiFiClass::WiFiClass()
174175
_init = 0;
175176
}
176177

178+
void WiFiClass::setPins(int8_t cs, int8_t irq, int8_t rst, int8_t en)
179+
{
180+
gi8Winc1501CsPin = cs;
181+
gi8Winc1501IntnPin = irq;
182+
gi8Winc1501ResetPin = rst;
183+
gi8Winc1501ChipEnPin = en;
184+
}
185+
177186
int WiFiClass::init()
178187
{
179188
tstrWifiInitParam param;

src/WiFi101.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class WiFiClass
8787

8888
WiFiClass();
8989

90+
void setPins(int8_t cs, int8_t irq, int8_t rst, int8_t en = -1);
91+
9092
int init();
9193

9294
char* firmwareVersion();

src/bsp/include/nm_bsp_arduino.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
*
3+
* \file
4+
*
5+
* \brief This module contains NMC1500 BSP APIs definitions.
6+
*
7+
* Copyright (c) 2015 Atmel Corporation. All rights reserved.
8+
*
9+
* \asf_license_start
10+
*
11+
* \page License
12+
*
13+
* Redistribution and use in source and binary forms, with or without
14+
* modification, are permitted provided that the following conditions are met:
15+
*
16+
* 1. Redistributions of source code must retain the above copyright notice,
17+
* this list of conditions and the following disclaimer.
18+
*
19+
* 2. Redistributions in binary form must reproduce the above copyright notice,
20+
* this list of conditions and the following disclaimer in the documentation
21+
* and/or other materials provided with the distribution.
22+
*
23+
* 3. The name of Atmel may not be used to endorse or promote products derived
24+
* from this software without specific prior written permission.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
27+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
29+
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
30+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36+
* POSSIBILITY OF SUCH DAMAGE.
37+
*
38+
* \asf_license_stop
39+
*
40+
*/
41+
42+
#ifndef _NM_BSP_ARDUINO_H_
43+
#define _NM_BSP_ARDUINO_H_
44+
45+
#include <stdint.h>
46+
47+
#include <Arduino.h>
48+
49+
/*
50+
* Arduino variants may redefine those pins.
51+
* If no pins are specified the following defaults are used:
52+
* WINC1501_RESET_PIN - pin 5
53+
* WINC1501_INTN_PIN - pin 7
54+
* WINC1501_CHIP_EN_PIN - not connected (tied to VCC)
55+
*/
56+
#if !defined(WINC1501_RESET_PIN)
57+
#define WINC1501_RESET_PIN 5
58+
#endif
59+
#if !defined(WINC1501_INTN_PIN)
60+
#define WINC1501_INTN_PIN 7
61+
#endif
62+
#if !defined(WINC1501_SPI_CS_PIN)
63+
#define WINC1501_SPI_CS_PIN 10
64+
#endif
65+
#if !defined(WINC1501_CHIP_EN_PIN)
66+
#define WINC1501_CHIP_EN_PIN -1
67+
#endif
68+
69+
extern int8_t gi8Winc1501CsPin;
70+
extern int8_t gi8Winc1501ResetPin;
71+
extern int8_t gi8Winc1501IntnPin;
72+
extern int8_t gi8Winc1501ChipEnPin;
73+
74+
#endif /* _NM_BSP_ARDUINO_H_ */

src/bsp/source/nm_bsp_arduino.c

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,13 @@
4343
*/
4444

4545
#include "bsp/include/nm_bsp.h"
46+
#include "bsp/include/nm_bsp_arduino.h"
4647
#include "common/include/nm_common.h"
47-
#include <Arduino.h>
4848

49-
/*
50-
* Arduino variants may redefine those pins.
51-
* If no pins are specified the following defaults are used:
52-
* WINC1501_RESET_PIN - pin 5
53-
* WINC1501_INTN_PIN - pin 7
54-
* WINC1501_CHIP_EN_PIN - not connected (tied to VCC)
55-
*/
56-
#if !defined(WINC1501_RESET_PIN)
57-
#define WINC1501_RESET_PIN 5
58-
#endif
59-
#if !defined(WINC1501_INTN_PIN)
60-
#define WINC1501_INTN_PIN 7
61-
#endif
49+
int8_t gi8Winc1501CsPin = WINC1501_SPI_CS_PIN;
50+
int8_t gi8Winc1501ResetPin = WINC1501_RESET_PIN;
51+
int8_t gi8Winc1501IntnPin = WINC1501_INTN_PIN;
52+
int8_t gi8Winc1501ChipEnPin = WINC1501_CHIP_EN_PIN;
6253

6354
static tpfNmBspIsr gpfIsr;
6455

@@ -88,17 +79,18 @@ static void chip_isr(void)
8879
*/
8980
static void init_chip_pins(void)
9081
{
91-
/* Configure RESETN D6 pins as output. */
92-
pinMode(WINC1501_RESET_PIN, OUTPUT);
93-
digitalWrite(WINC1501_RESET_PIN, HIGH);
82+
/* Configure RESETN pin as output. */
83+
pinMode(gi8Winc1501ResetPin, OUTPUT);
84+
digitalWrite(gi8Winc1501ResetPin, HIGH);
9485

95-
/* Configure INTN D7 pins as pinput. */
96-
pinMode(WINC1501_INTN_PIN, INPUT);
86+
/* Configure INTN pins as input. */
87+
pinMode(gi8Winc1501IntnPin, INPUT);
9788

98-
#if defined(WINC1501_CHIP_EN_PIN)
99-
/* Configure CHIP_EN as pull-up */
100-
pinMode(WINC1501_CHIP_EN_PIN, INPUT_PULLUP);
101-
#endif
89+
if (gi8Winc1501ChipEnPin > -1)
90+
{
91+
/* Configure CHIP_EN as pull-up */
92+
pinMode(gi8Winc1501ChipEnPin, INPUT_PULLUP);
93+
}
10294
}
10395

10496
/*
@@ -143,9 +135,9 @@ sint8 nm_bsp_deinit(void)
143135
*/
144136
void nm_bsp_reset(void)
145137
{
146-
digitalWrite(WINC1501_RESET_PIN, LOW);
138+
digitalWrite(gi8Winc1501ResetPin, LOW);
147139
nm_bsp_sleep(100);
148-
digitalWrite(WINC1501_RESET_PIN, HIGH);
140+
digitalWrite(gi8Winc1501ResetPin, HIGH);
149141
nm_bsp_sleep(100);
150142
}
151143

@@ -178,7 +170,7 @@ void nm_bsp_sleep(uint32 u32TimeMsec)
178170
void nm_bsp_register_isr(tpfNmBspIsr pfIsr)
179171
{
180172
gpfIsr = pfIsr;
181-
attachInterruptMultiArch(WINC1501_INTN_PIN, chip_isr, FALLING);
173+
attachInterruptMultiArch(gi8Winc1501IntnPin, chip_isr, FALLING);
182174
}
183175

184176
/*
@@ -193,8 +185,8 @@ void nm_bsp_register_isr(tpfNmBspIsr pfIsr)
193185
void nm_bsp_interrupt_ctrl(uint8 u8Enable)
194186
{
195187
if (u8Enable) {
196-
attachInterruptMultiArch(WINC1501_INTN_PIN, chip_isr, FALLING);
188+
attachInterruptMultiArch(gi8Winc1501IntnPin, chip_isr, FALLING);
197189
} else {
198-
detachInterruptMultiArch(WINC1501_INTN_PIN);
190+
detachInterruptMultiArch(gi8Winc1501IntnPin);
199191
}
200192
}

src/bsp/source/nm_bsp_arduino_avr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
#ifdef ARDUINO_ARCH_AVR
4646

4747
#include "bsp/include/nm_bsp.h"
48+
#include "bsp/include/nm_bsp_arduino.h"
4849
#include "common/include/nm_common.h"
49-
#include <Arduino.h>
5050

5151
#define IS_MEGA (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560))
5252

src/bus_wrapper/source/nm_bus_wrapper_samd21.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,15 @@
4949
* Variants may define an alternative SPI instace to use for WiFi101.
5050
* If not defined the following defaults are used:
5151
* WINC1501_SPI - SPI
52-
* WINC1501_CS_PIN - pin 10
5352
*/
5453
#if !defined(WINC1501_SPI)
5554
#define WINC1501_SPI SPI
5655
#endif
57-
#if !defined(WINC1501_SPI_CS_PIN)
58-
#define WINC1501_SPI_CS_PIN 10
59-
#endif
6056

6157
extern "C" {
6258

6359
#include "bsp/include/nm_bsp.h"
60+
#include "bsp/include/nm_bsp_arduino.h"
6461
#include "common/include/nm_common.h"
6562
#include "bus_wrapper/include/nm_bus_wrapper.h"
6663

@@ -93,7 +90,7 @@ static sint8 spi_rw(uint8* pu8Mosi, uint8* pu8Miso, uint16 u16Sz)
9390
}
9491

9592
WINC1501_SPI.beginTransaction(wifi_SPISettings);
96-
digitalWrite(WINC1501_SPI_CS_PIN, LOW);
93+
digitalWrite(gi8Winc1501CsPin, LOW);
9794

9895
while (u16Sz) {
9996
*pu8Miso = WINC1501_SPI.transfer(*pu8Mosi);
@@ -105,7 +102,7 @@ static sint8 spi_rw(uint8* pu8Mosi, uint8* pu8Miso, uint16 u16Sz)
105102
pu8Mosi++;
106103
}
107104

108-
digitalWrite(WINC1501_SPI_CS_PIN, HIGH);
105+
digitalWrite(gi8Winc1501CsPin, HIGH);
109106
WINC1501_SPI.endTransaction();
110107

111108
return M2M_SUCCESS;
@@ -129,8 +126,8 @@ sint8 nm_bus_init(void * /* pvInitValue */)
129126
WINC1501_SPI.begin();
130127

131128
/* Configure CS PIN. */
132-
pinMode(WINC1501_SPI_CS_PIN, OUTPUT);
133-
digitalWrite(WINC1501_SPI_CS_PIN, HIGH);
129+
pinMode(gi8Winc1501CsPin, OUTPUT);
130+
digitalWrite(gi8Winc1501CsPin, HIGH);
134131

135132
/* Reset WINC1500. */
136133
nm_bsp_reset();

0 commit comments

Comments
 (0)