Skip to content

Commit

Permalink
esp_wifi working partial bindings, enable drawer & wifi again
Browse files Browse the repository at this point in the history
  • Loading branch information
Reavershark committed Jul 21, 2024
1 parent d3c86f2 commit 06f2c5a
Show file tree
Hide file tree
Showing 25 changed files with 1,955 additions and 74 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/idf-project/*/build
/idf-project/*/sdkconfig
/idf-project/*/sdkconfig.old

.dub
*.a
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"d.dubCompiler": "/opt/ldc-xtensa/bin/ldc2",
"d.dubArchType": "xtensa-esp32",
"d.dubArchType": "xtensa-esp32-none-elf",
"d.stdlibPath": [
"/opt/ldc-xtensa/include/d"
],
Expand Down
1 change: 1 addition & 0 deletions idf-project/debug/partitions.csv
2 changes: 2 additions & 0 deletions idf-project/debug/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#CONFIG_PARTITION_TABLE_CUSTOM=y
#CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
3 changes: 3 additions & 0 deletions idf-project/main.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
idf_component_register(
SRCS
"../../../source/idfd/signalio/idfd_signalio_i2s_c_code.c"
"../../../source/idf/esp_wifi/idf_esp_wifi_c_code.c"
"../../../source/idf/sys/socket/idf_sys_socket_c_code.c"
INCLUDE_DIRS "."
)
target_link_libraries("${COMPONENT_LIB}" "${PROJECT_DIR}/dcode.a")
target_link_options("${COMPONENT_LIB}" INTERFACE "-Wl,--start-group") # Allow forward references during linkage
#target_link_options("${COMPONENT_LIB}" INTERFACE "-Wl,--print-gc-sections")
5 changes: 5 additions & 0 deletions idf-project/partitions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Name, Type, SubType, Offset, Size, Flags
# 4M total
nvs, data, nvs, , 0x6000,
phy_init, data, phy, , 0x1000,
factory, app, factory, , 0x3F0000,
1 change: 1 addition & 0 deletions idf-project/release/partitions.csv
4 changes: 3 additions & 1 deletion idf-project/release/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
CONFIG_COMPILER_OPTIMIZATION_PERF=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=n
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
#CONFIG_PARTITION_TABLE_CUSTOM=y
#CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
6 changes: 3 additions & 3 deletions source/app/http.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import idf.sys.socket : accept, AF_INET, bind, close, connect, htonl, htons, IPA
import idfd.log : Logger;

import ministd.string : startsWith;
import ministd.typecons : UniqueHeapArray;
import ministd.typecons : UniqueHeapArray, SharedHeap;

@safe nothrow @nogc:

Expand All @@ -22,11 +22,11 @@ struct HttpServer
private ushort m_port;
private int m_listenSocket;
private long m_recvTimeoutUsecs;
private Drawer* m_drawer;
private SharedHeap!Drawer m_drawer;

@disable this();

this(Drawer* drawer, ushort port, long recvTimeoutUsecs = 2_000_000)
this(SharedHeap!Drawer drawer, ushort port, long recvTimeoutUsecs = 2_000_000)
{
m_drawer = drawer;
m_port = port;
Expand Down
46 changes: 24 additions & 22 deletions source/app/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import idfd.signalio.i2s : I2SSignalGenerator;
import idfd.signalio.router : route;
import idfd.signalio.signal : Signal;

import ministd.typecons : UniqueHeapArray;
import ministd.typecons : UniqueHeapArray, SharedHeap;

// dfmt off
@safe:
Expand All @@ -38,35 +38,35 @@ struct TScherm(TSchermCTConfig ctConfig)
private enum log = Logger!"TScherm"();

private const TSchermRTConfig m_rtConfig;
private FrameBuffer m_fb;
private SharedHeap!FrameBuffer m_fb;
private DMADescriptorRing m_dmaDescriptorRing;
private I2SSignalGenerator m_signalGenerator;
// private Drawer m_drawer;
// private WiFiClient m_wifiClient;
// private HttpServer m_httpServer;
private SharedHeap!Drawer m_drawer;
private WiFiClient m_wifiClient;
private HttpServer m_httpServer;

this(const TSchermRTConfig rtConfig)
{
m_rtConfig = rtConfig;

// Init network async
{
// m_wifiClient = WiFiClient(rtConfig.ssid, rtConfig.password);
// m_wifiClient.startAsync;
log.info!"Initializing network (async)";

m_wifiClient = WiFiClient(rtConfig.ssid, rtConfig.password);
m_wifiClient.startAsync;
}

// Init VGA
{
log.info!"initializing VGA";
log.info!"Initializing VGA";

m_fb = FrameBuffer(m_rtConfig.vt);
m_fb = SharedHeap!FrameBuffer.create(m_rtConfig.vt);
m_signalGenerator = I2SSignalGenerator(
i2sIndex: 1,
bitCount: 8,
freq: m_rtConfig.vt.pixelClock,
);
m_dmaDescriptorRing = DMADescriptorRing(m_rtConfig.vt.v.total);
m_dmaDescriptorRing.setBuffers((() @trusted => cast(ubyte[][]) m_fb.linesWithSync)());
m_dmaDescriptorRing.setBuffers((() @trusted => cast(ubyte[][]) m_fb.get.linesWithSync)());

UniqueHeapArray!Signal signals = m_signalGenerator.getSignals;
// route(from: signals.get[0], to: GPIOPin(m_rtConfig.redPin ), invert: false); // Red
Expand All @@ -80,21 +80,23 @@ struct TScherm(TSchermCTConfig ctConfig)

m_signalGenerator.startTransmitting(m_dmaDescriptorRing.firstDescriptor);

// m_drawer = Drawer(&m_fb);
m_drawer = SharedHeap!Drawer.create(m_fb);

log.info!"VGA initialization complete";
}

// Wait for async network init to complete
{
// m_wifiClient.waitForConnection;
log.info!"Waiting for network to initialize";

m_wifiClient.waitForConnection;

// log.info!"Network initialization complete";
log.info!"Network initialization complete";
}

{
// m_httpServer = HttpServer(&m_drawer, m_rtConfig.httpPort);
// m_httpServer.start;
log.info!"Starting http server (in another task)";
m_httpServer = HttpServer(m_drawer, m_rtConfig.httpPort);
m_httpServer.start;
}
}

Expand Down Expand Up @@ -132,10 +134,10 @@ void app_main()
tScherm.m_fb.fill(Color.WHITE);
pause(200);

tScherm.drawImage!"zeus.raw";
pause(800);
tScherm.drawImage!"reavershark.raw";
pause(800);
// tScherm.drawImage!"zeus.raw";
// pause(800);
// tScherm.drawImage!"reavershark.raw";
// pause(800);

tScherm.m_fb.fillIteratingColorsDiagonal!"x+y/vDivide";
pause(200);
Expand Down
24 changes: 14 additions & 10 deletions source/app/vga/draw.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,37 @@ import app.vga.framebuffer : FrameBuffer;
import idfd.log : Logger;

import ministd.traits : isInstanceOf;
import ministd.typecons : SharedHeap;

@safe nothrow @nogc:

struct Box
{
size_t x1, x2, y1, y2;

bool valid() const pure => x1 < x2 && y1 < y2;
const pure nothrow @nogc:

size_t width() const pure => x2 - x1;
size_t height() const pure => y2 - y1;
bool valid() => x1 < x2 && y1 < y2;

size_t width() => x2 - x1;
size_t height() => y2 - y1;
}

struct Drawer
{
@nogc:
private enum log = Logger!"Drawer"();

private FrameBuffer* m_fb;
private SharedHeap!FrameBuffer m_fb;
private Color m_backgroundColor;
private size_t m_separatorX;
private Color m_separatorColor;
private Color m_textColor;

@disable this();

this(FrameBuffer* fb)
in (fb !is null)
this(SharedHeap!FrameBuffer fb)
in (!fb.empty)
{
m_fb = fb;

Expand Down Expand Up @@ -64,7 +68,7 @@ struct Drawer
in (m_separatorX < m_fb.activeWidth)
{
foreach (y; 0 .. m_fb.activeHeight)
(*m_fb)[y, m_separatorX] = m_separatorColor;
m_fb[y, m_separatorX] = m_separatorColor;
}

private void scrollBoxDown(
Expand All @@ -84,9 +88,9 @@ struct Drawer
foreach (x; box.x1 .. box.x2)
{
if (y + amount < box.y2)
(*m_fb)[y, x] = (*m_fb)[y + amount, x];
m_fb[y, x] = m_fb[y + amount, x];
else
(*m_fb)[y, x] = background;
(m_fb)[y, x] = background;
}
}

Expand All @@ -110,7 +114,7 @@ struct Drawer
foreach (x; 0 .. font.glyphWidth)
{
Color color = glyph[y][x] > 0x80 ? m_textColor : m_backgroundColor;
(*m_fb)[box.y1 + y, box.x1 + xOffset + x] = color;
m_fb[box.y1 + y, box.x1 + xOffset + x] = color;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion source/app/vga/framebuffer.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ministd.heap_caps : dallocArrayCaps;

struct FrameBuffer
{
@nogc:
enum log = Logger!"FrameBuffer"();

private const VideoTimings m_vt;
Expand Down Expand Up @@ -125,7 +126,7 @@ struct FrameBuffer

void fillIteratingColorsDiagonal(string indexFunc = "x+y/vDivide")()
{
immutable Color[] colors = [
static immutable Color[] colors = [
Color.WHITE, Color.BLACK,
];

Expand Down
19 changes: 10 additions & 9 deletions source/app/vga/video_timings.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ struct VideoTimings
{
struct Dimension
{
const pure nothrow @nogc:
uint front, sync, back, res;
uint total() const pure => front + sync + back + res;
uint frontStart() const pure => 0;
uint frontEnd() const pure => front;
uint syncStart() const pure => front;
uint syncEnd() const pure => front + sync;
uint backStart() const pure => front + sync;
uint backEnd() const pure => front + sync + back;
uint resStart() const pure => front + sync + back;
uint resEnd() const pure => front + sync + back + res;
uint total() => front + sync + back + res;
uint frontStart() => 0;
uint frontEnd() => front;
uint syncStart() => front;
uint syncEnd() => front + sync;
uint backStart() => front + sync;
uint backEnd() => front + sync + back;
uint resStart() => front + sync + back;
uint resEnd() => front + sync + back + res;
}

ulong pixelClock;
Expand Down
11 changes: 11 additions & 0 deletions source/idf/esp_hw_support/esp_interface.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module idf.esp_hw_support.esp_interface;

@safe pure nothrow extern(C):

enum esp_interface_t
{
ESP_IF_WIFI_STA = 0, /**< ESP32 station interface */
ESP_IF_WIFI_AP, /**< ESP32 soft-AP interface */
ESP_IF_ETH, /**< ESP32 ethernet interface */
ESP_IF_MAX
}
64 changes: 64 additions & 0 deletions source/idf/esp_netif/package.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module idf.esp_netif;

import idf.esp_common.esp_err : esp_err_t;
import idf.esp_event : esp_event_base_t;

@safe nothrow @nogc extern (C):
// dfmt off

alias esp_netif_t = void;

/** IP event declarations */
enum ip_event_t
{
IP_EVENT_STA_GOT_IP, /*!< station got IP from connected AP */
IP_EVENT_STA_LOST_IP, /*!< station lost IP and the IP is reset to 0 */
IP_EVENT_AP_STAIPASSIGNED, /*!< soft-AP assign an IP to a connected station */
IP_EVENT_GOT_IP6, /*!< station or ap or ethernet interface v6IP addr is preferred */
IP_EVENT_ETH_GOT_IP, /*!< ethernet got IP from connected AP */
IP_EVENT_ETH_LOST_IP, /*!< ethernet lost IP and the IP is reset to 0 */
IP_EVENT_PPP_GOT_IP, /*!< PPP interface got IP */
IP_EVENT_PPP_LOST_IP, /*!< PPP interface lost IP */
}

/**
* @brief IPv4 address
*
*/
struct esp_ip4_addr_t
{
uint addr; /*!< IPv4 address */
}

struct esp_netif_ip_info_t
{
esp_ip4_addr_t ip; /**< Interface IPV4 address */
esp_ip4_addr_t netmask; /**< Interface IPV4 netmask */
esp_ip4_addr_t gw; /**< Interface IPV4 gateway address */
}

/**
* @brief Event structure for IP_EVENT_GOT_IP event
*
*/
struct ip_event_got_ip_t
{
int if_index; /*!< Interface index for which the event is received (left for legacy compilation) */
esp_netif_t* esp_netif; /*!< Pointer to corresponding esp-netif object */
esp_netif_ip_info_t ip_info; /*!< IP address, netmask, gatway IP address */
bool ip_changed; /*!< Whether the assigned IP has changed or not */
}

/**
* @brief Initialize the underlying TCP/IP stack
*
* @return
* - ESP_OK on success
* - ESP_FAIL if initializing failed
* @note This function should be called exactly once from application code, when the application starts up.
*/
esp_err_t esp_netif_init();

/** @brief IP event base declaration */
extern __gshared esp_event_base_t IP_EVENT;
Loading

0 comments on commit 06f2c5a

Please sign in to comment.