Skip to content

Commit 602f69c

Browse files
committed
[h89] commstst
1 parent f8116f8 commit 602f69c

File tree

1 file changed

+77
-54
lines changed

1 file changed

+77
-54
lines changed

lib/bus/h89/h89.cpp

Lines changed: 77 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "fnSystem.h"
1616

1717
#include "led.h"
18-
#include "modem.h"
18+
#include "modem.h"
1919

2020
#include "driver/gpio.h"
2121

@@ -28,8 +28,8 @@
2828
#define D6 GPIO_NUM_12
2929
#define D7 GPIO_NUM_13
3030

31-
#define OE GPIO_NUM_0
32-
#define DIR GPIO_NUM_2
31+
#define OE GPIO_NUM_0
32+
#define _DIR GPIO_NUM_2
3333
#define STB GPIO_NUM_4
3434
#define ACK GPIO_NUM_15
3535
#define IBF GPIO_NUM_34
@@ -52,8 +52,7 @@ void virtualDevice::process(uint32_t commanddata, uint8_t checksum)
5252
*/
5353
int systemBus::bus_available()
5454
{
55-
// OBF is inverted.
56-
return !gpio_get_level(OBF);
55+
return gpio_get_level(OBF);
5756
}
5857

5958
/**
@@ -64,8 +63,13 @@ int systemBus::port_getc()
6463
{
6564
int val=0;
6665

66+
if (gpio_get_level(OE))
67+
{
68+
return -1;
69+
}
70+
6771
// Fail if nothing waiting.
68-
if (!bus_available())
72+
if (bus_available())
6973
return -1;
7074

7175
gpio_set_level(ACK,DIGI_LOW);
@@ -78,7 +82,7 @@ int systemBus::port_getc()
7882
val |= gpio_get_level(D5) << 5;
7983
val |= gpio_get_level(D6) << 6;
8084
val |= gpio_get_level(D7) << 7;
81-
85+
8286
gpio_set_level(ACK,DIGI_HIGH);
8387

8488
return val;
@@ -130,9 +134,6 @@ uint16_t systemBus::port_getbuf(void *buf, uint16_t len, uint16_t timeout)
130134
*/
131135
int systemBus::port_putc(uint8_t c)
132136
{
133-
if (gpio_get_level(OE) == DIGI_HIGH)
134-
return -1; // Output not enabled by computer. Abort.
135-
136137
// Wait for IBF to be low.
137138
while(gpio_get_level(IBF) == DIGI_HIGH);
138139

@@ -154,7 +155,7 @@ int systemBus::port_putc(uint8_t c)
154155

155156
// Desert strobe
156157
gpio_set_level(STB,DIGI_HIGH);
157-
158+
158159
return c;
159160
}
160161

@@ -180,59 +181,81 @@ uint16_t systemBus::port_putbuf(const void *buf, uint16_t len)
180181
}
181182
return l;
182183
}
184+
185+
uint8_t ctrl_state = 0;
186+
uint8_t ctrl_state_prev = 0;
187+
188+
const char msg[] = "TEST FROM ESP32!\r\n";
183189

184190
void systemBus::service()
185191
{
186-
const char msg[] = "THIS IS SENT FROM ESP32!\r\n";
192+
ctrl_state = gpio_get_level(OBF);
193+
ctrl_state |= gpio_get_level(ACK) << 1;
194+
ctrl_state |= gpio_get_level(IBF) << 2;
195+
ctrl_state |= gpio_get_level(STB) << 3;
187196

188-
while(1)
197+
if (ctrl_state != ctrl_state_prev)
189198
{
190-
port_putbuf((void *)msg,strlen(msg));
199+
// Debug_printf("New ctrl_state = '%02X'\n",ctrl_state);
191200
}
201+
202+
ctrl_state_prev = ctrl_state;
203+
204+
if (bus_available())
205+
{
206+
while (bus_available())
207+
{
208+
int c = port_getc_timeout(10);
209+
Debug_printf("%c",c);
210+
//port_putc(c);
211+
}
212+
}
213+
214+
// port_putbuf(msg,strlen(msg));
192215
}
193-
216+
194217
void systemBus::setup()
195218
{
196219
Debug_println("H89 SETUP\n");
197-
Debug_println("TX\n");
198-
199-
// // Reset pins
200-
gpio_reset_pin(GPIO_NUM_0);
201-
gpio_reset_pin(GPIO_NUM_2);
202-
gpio_reset_pin(GPIO_NUM_4);
203-
gpio_reset_pin(GPIO_NUM_12);
204-
gpio_reset_pin(GPIO_NUM_13);
205-
gpio_reset_pin(GPIO_NUM_14);
206-
gpio_reset_pin(GPIO_NUM_15);
207-
gpio_reset_pin(GPIO_NUM_22);
208-
gpio_reset_pin(GPIO_NUM_25);
209-
gpio_reset_pin(GPIO_NUM_26);
210-
gpio_reset_pin(GPIO_NUM_27);
211-
gpio_reset_pin(GPIO_NUM_32);
212-
gpio_reset_pin(GPIO_NUM_33);
213-
gpio_reset_pin(GPIO_NUM_34);
214-
215-
gpio_set_direction(GPIO_NUM_0,GPIO_MODE_INPUT);
216-
gpio_set_direction(GPIO_NUM_2,GPIO_MODE_INPUT);
217-
gpio_set_direction(GPIO_NUM_4,GPIO_MODE_OUTPUT);
218-
gpio_set_direction(GPIO_NUM_12,GPIO_MODE_INPUT_OUTPUT);
219-
gpio_set_direction(GPIO_NUM_13,GPIO_MODE_INPUT_OUTPUT);
220-
gpio_set_direction(GPIO_NUM_14,GPIO_MODE_INPUT_OUTPUT);
221-
gpio_set_direction(GPIO_NUM_15,GPIO_MODE_OUTPUT);
222-
gpio_set_direction(GPIO_NUM_22,GPIO_MODE_INPUT_OUTPUT);
223-
gpio_set_direction(GPIO_NUM_25,GPIO_MODE_INPUT_OUTPUT);
224-
gpio_set_direction(GPIO_NUM_26,GPIO_MODE_INPUT_OUTPUT);
225-
gpio_set_direction(GPIO_NUM_27,GPIO_MODE_INPUT_OUTPUT);
226-
gpio_set_direction(GPIO_NUM_32,GPIO_MODE_INPUT_OUTPUT);
227-
gpio_set_direction(GPIO_NUM_33,GPIO_MODE_INPUT_OUTPUT);
228-
gpio_set_direction(GPIO_NUM_34,GPIO_MODE_INPUT);
229-
gpio_set_direction(GPIO_NUM_35,GPIO_MODE_INPUT);
230-
231-
Debug_printf("Setting GPIO #15 (/ACK) to high.");
232-
gpio_set_level(GPIO_NUM_15,DIGI_HIGH);
233-
234-
gpio_set_level(GPIO_NUM_4,DIGI_HIGH);
235-
Debug_printf("GPIO #4 (/STB) SET HIGH.\n");
220+
Debug_println("COMMSTST\n\n");
221+
222+
// Reset these pins to INPUT.
223+
gpio_reset_pin(OE);
224+
gpio_reset_pin(_DIR);
225+
gpio_reset_pin(STB);
226+
gpio_reset_pin(D6);
227+
gpio_reset_pin(D7);
228+
gpio_reset_pin(D5);
229+
gpio_reset_pin(ACK);
230+
gpio_reset_pin(D2);
231+
gpio_reset_pin(D3);
232+
gpio_reset_pin(D4);
233+
gpio_reset_pin(D0);
234+
gpio_reset_pin(D1);
235+
gpio_reset_pin(IBF);
236+
gpio_reset_pin(OBF);
237+
gpio_reset_pin(GPIO_NUM_22); // See if we can remove this?
238+
239+
// Adjust appropriate pins to INPUT, OUTPUT, or INPUT_OUTPUT.
240+
gpio_set_direction(OE,GPIO_MODE_INPUT);
241+
gpio_set_direction(_DIR,GPIO_MODE_INPUT);
242+
gpio_set_direction(STB,GPIO_MODE_OUTPUT);
243+
gpio_set_direction(D6,GPIO_MODE_INPUT_OUTPUT);
244+
gpio_set_direction(D7,GPIO_MODE_INPUT_OUTPUT);
245+
gpio_set_direction(D5,GPIO_MODE_INPUT_OUTPUT);
246+
gpio_set_direction(ACK,GPIO_MODE_OUTPUT);
247+
gpio_set_direction(D2,GPIO_MODE_INPUT_OUTPUT);
248+
gpio_set_direction(D3,GPIO_MODE_INPUT_OUTPUT);
249+
gpio_set_direction(D4,GPIO_MODE_INPUT_OUTPUT);
250+
gpio_set_direction(D0,GPIO_MODE_INPUT_OUTPUT);
251+
gpio_set_direction(D1,GPIO_MODE_INPUT_OUTPUT);
252+
gpio_set_direction(IBF,GPIO_MODE_INPUT);
253+
gpio_set_direction(OBF,GPIO_MODE_INPUT);
254+
gpio_set_direction(GPIO_NUM_22,GPIO_MODE_INPUT_OUTPUT); // can we remove this?
255+
256+
// Reset /ACK and /STB
257+
gpio_set_level(ACK,DIGI_HIGH);
258+
gpio_set_level(STB,DIGI_HIGH);
236259

237260
Debug_printf("GPIO CONFIGURED\n");
238261
}

0 commit comments

Comments
 (0)