mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-31 13:00:49 +00:00
77 lines
1.9 KiB
C
77 lines
1.9 KiB
C
// SPDX-FileCopyrightText: 2026 Cesanta Software Limited
|
|
// SPDX-License-Identifier: GPL-2.0-only or commercial
|
|
// Generated by Mongoose Wizard, https://mongoose.ws/wizard/
|
|
|
|
#include "hal.h"
|
|
#include "mongoose.h"
|
|
|
|
#ifndef WIFI_NAME
|
|
#define WIFI_NAME ""
|
|
#endif
|
|
|
|
#ifndef WIFI_PASS
|
|
#define WIFI_PASS ""
|
|
#endif
|
|
|
|
#ifndef WIFI_AP_NAME
|
|
#define WIFI_AP_NAME "Mongoose"
|
|
#endif
|
|
|
|
#ifndef WIFI_AP_PASS
|
|
#define WIFI_AP_PASS "mongoose"
|
|
#endif
|
|
|
|
#ifndef ENABLE_WIFI_AP
|
|
#define ENABLE_WIFI_AP 1
|
|
#endif
|
|
|
|
static bool hwspecific_is_ready(void) {
|
|
return hal_gpio_read(SPI_RDY);
|
|
}
|
|
|
|
static void hwspecific_spi_begin(void *arg) {
|
|
hal_spi_select(WIFISPI, true);
|
|
(void) arg;
|
|
}
|
|
|
|
static void hwspecific_spi_txn(void *arg, uint8_t *txdata, uint8_t *rxdata, size_t len) {
|
|
while (len--) {
|
|
uint8_t rx = hal_spi_xfer_byte(WIFISPI, txdata != NULL ? *txdata++ : 0);
|
|
if (rxdata != NULL) *rxdata++ = rx;
|
|
}
|
|
hal_spi_done(WIFISPI);
|
|
(void) arg;
|
|
}
|
|
|
|
static void hwspecific_spi_end(void *arg) {
|
|
hal_spi_select(WIFISPI, false);
|
|
(void) arg;
|
|
}
|
|
|
|
void hwspecific_spi_init(void) {
|
|
hal_gpio_output(SPI_CHIP_EN);
|
|
hal_gpio_write(SPI_CHIP_EN, 0);
|
|
hal_gpio_input(SPI_RDY);
|
|
hal_spi_init(WIFISPI, 128); // runs at 1.25MHz (SYS_CLK/128)
|
|
mg_delayms(10);
|
|
hal_gpio_write(SPI_CHIP_EN, 1);
|
|
}
|
|
|
|
static const struct mg_tcpip_spi spi = {NULL, hwspecific_spi_begin, hwspecific_spi_end, hwspecific_spi_txn};
|
|
|
|
void wifi_setconfig(void *data) {
|
|
struct mg_tcpip_driver_st67w6_data *d = (struct mg_tcpip_driver_st67w6_data *) data;
|
|
d->wifi.ssid = WIFI_NAME;
|
|
d->wifi.pass = WIFI_PASS;
|
|
d->wifi.apssid = WIFI_AP_NAME;
|
|
d->wifi.appass = WIFI_AP_PASS;
|
|
d->wifi.apip = MG_IPV4(192, 168, 169, 1);
|
|
d->wifi.apmask = MG_IPV4(255, 255, 255, 0);
|
|
d->wifi.security = 0;
|
|
d->wifi.apsecurity = 0;
|
|
d->wifi.apchannel = 10;
|
|
d->wifi.apmode = ENABLE_WIFI_AP;
|
|
d->spi = (struct mg_tcpip_spi *) &spi;
|
|
d->is_ready = hwspecific_is_ready;
|
|
}
|