Skip to content

Commit 8385fec

Browse files
committed
[h89][bus] functions now work.
1 parent 654927f commit 8385fec

File tree

1 file changed

+59
-120
lines changed

1 file changed

+59
-120
lines changed

lib/bus/h89/h89.cpp

Lines changed: 59 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void virtualDevice::process(uint32_t commanddata, uint8_t checksum)
4141
cmdFrame.checksum = checksum;
4242

4343

44-
fnUartDebug.printf("process() not implemented yet for this device. Cmd received: %02x\n", cmdFrame.comnd);
44+
Debug_printf("process() not implemented yet for this device. Cmd received: %02x\n", cmdFrame.comnd);
4545
}
4646

4747
#define ACK GPIO_NUM_15
@@ -123,139 +123,78 @@ uint16_t systemBus::port_getbuf(void *buf, uint16_t len, uint16_t timeout)
123123
return l;
124124
}
125125

126-
void systemBus::service()
126+
/**
127+
* @brief Put character
128+
* @param c Character to send
129+
* @return character sent, or -1 if not able to send.
130+
*/
131+
int systemBus::port_putc(uint8_t c)
127132
{
128-
// printf("Set byte to: 0x%02X\r\n",xbyte);
129-
130-
// // This is the transmit routine
131-
// gpio_set_level(D7,xbyte & 0x80 ? DIGI_HIGH : DIGI_LOW);
132-
// gpio_set_level(D6,xbyte & 0x40 ? DIGI_HIGH : DIGI_LOW);
133-
// gpio_set_level(D5,xbyte & 0x20 ? DIGI_HIGH : DIGI_LOW);
134-
// gpio_set_level(D4,xbyte & 0x10 ? DIGI_HIGH : DIGI_LOW);
135-
// gpio_set_level(D3,xbyte & 0x08 ? DIGI_HIGH : DIGI_LOW);
136-
// gpio_set_level(D2,xbyte & 0x04 ? DIGI_HIGH : DIGI_LOW);
137-
// gpio_set_level(D1,xbyte & 0x02 ? DIGI_HIGH : DIGI_LOW);
138-
// gpio_set_level(D0,xbyte & 0x01 ? DIGI_HIGH : DIGI_LOW);
139-
140-
141-
// // set STB to low
142-
// printf("Set STB To low \r\n");
143-
// gpio_set_level(STB,DIGI_LOW);
133+
if (gpio_get_level(OE) == DIGI_HIGH)
134+
return -1; // Output not enabled by computer. Abort.
135+
136+
// Wait for IBF to be low.
137+
while(gpio_get_level(IBF) == DIGI_HIGH);
138+
139+
// Set data bits
140+
gpio_set_level(D7,c & 0x80 ? DIGI_HIGH : DIGI_LOW);
141+
gpio_set_level(D6,c & 0x40 ? DIGI_HIGH : DIGI_LOW);
142+
gpio_set_level(D5,c & 0x20 ? DIGI_HIGH : DIGI_LOW);
143+
gpio_set_level(D4,c & 0x10 ? DIGI_HIGH : DIGI_LOW);
144+
gpio_set_level(D3,c & 0x08 ? DIGI_HIGH : DIGI_LOW);
145+
gpio_set_level(D2,c & 0x04 ? DIGI_HIGH : DIGI_LOW);
146+
gpio_set_level(D1,c & 0x02 ? DIGI_HIGH : DIGI_LOW);
147+
gpio_set_level(D0,c & 0x01 ? DIGI_HIGH : DIGI_LOW);
148+
149+
// Strobe to trigger latch (inverted)
150+
gpio_set_level(STB,DIGI_LOW);
151+
152+
// Wait for IBF to indicate that 8255 has accepted byte
153+
while(gpio_get_level(IBF) == DIGI_LOW);
154+
155+
// Desert strobe
156+
gpio_set_level(STB,DIGI_HIGH);
157+
158+
return c;
159+
}
144160

145-
// // Wait for IBF to go HIGH
146-
// printf("Wait for IBF to go HIGH\r\n");
147-
// while(gpio_get_level(IBF) == DIGI_LOW);
161+
/**
162+
* @brief Put buffer
163+
* @param buf pointer to buffer to send
164+
* @param len Length of buffer to send
165+
* @return number of bytes actually sent.
166+
*/
167+
uint16_t systemBus::port_putbuf(void *buf, uint16_t len)
168+
{
169+
uint16_t l = 0;
170+
uint8_t *p = (uint8_t *)buf;
148171

149-
// // set STB to high
150-
// printf("Set STB to HIGH\r\n");
151-
// gpio_set_level(STB,DIGI_HIGH);
172+
while (len--)
173+
{
174+
int c = port_putc(*p++);
152175

153-
// // Wait for IBF to go LOW
154-
// printf("Wait for IBF to go LOW\r\n");
155-
// while(gpio_get_level(IBF) == DIGI_HIGH);
176+
if (c<0)
177+
break;
156178

157-
// // Increment xbyte and go again...
158-
// printf("Increment xbyte and go again...\r\n");
159-
// xbyte++;
179+
l++;
180+
}
181+
return l;
182+
}
160183

161-
////////////////////////////////////////////////////////////////////////////
184+
void systemBus::service()
185+
{
186+
const char msg[] = "THIS IS SENT FROM ESP32!\r\n";
162187

163-
if (bus_available())
188+
while(1)
164189
{
165-
int c = port_getc();
166-
Debug_printf("RX: '%c' 0x%02X\n",c,c);
190+
port_putbuf((void *)msg,strlen(msg));
167191
}
168-
169-
////////////////////////////////////////////////////////////////////////////
170-
// THIS IS THE RECEIVE ROUTINE. IT WORKS!
171-
// /STB is set high in ::setup()
172-
173-
// // Wait for /OBF to go high
174-
// Debug_printf("Wait for OBF to go high.\r\n");
175-
// while (gpio_get_level(GPIO_NUM_35) == DIGI_HIGH);
176-
177-
// Debug_printf("OBF Low\n Setting ACK LOW\r\n");
178-
179-
// // Set /ACK low.
180-
// gpio_set_level(ACK,DIGI_LOW);
181-
// quick_delay();
182-
183-
// Debug_printf("Waited 1us, sampling D0-D7\r\n");
184-
185-
// // sample and output bus state on console.
186-
// printf("LOW: ");
187-
// printf("%u",gpio_get_level(GPIO_NUM_13));
188-
// printf("%u",gpio_get_level(GPIO_NUM_12));
189-
// printf("%u",gpio_get_level(GPIO_NUM_14));
190-
// printf("%u",gpio_get_level(GPIO_NUM_27));
191-
// printf("%u",gpio_get_level(GPIO_NUM_26));
192-
// printf("%u",gpio_get_level(GPIO_NUM_25));
193-
// printf("%u",gpio_get_level(GPIO_NUM_33));
194-
// printf("%u\n",gpio_get_level(GPIO_NUM_32));
195-
196-
// Debug_printf("Setting /ACK high again.\r\n");
197-
198-
// // Set /ACK high again.
199-
// gpio_set_level(ACK,DIGI_HIGH);
200-
// quick_delay();
201-
202-
// Debug_printf("Waiting for OBF to go high\r\n");
203-
204-
// // Wait for /OBF to go low
205-
// while (gpio_get_level(GPIO_NUM_35) == DIGI_LOW);
206-
207-
// Debug_printf("OBF now high. Sampling bus.\r\n");
208-
209-
// // sample and output bus state on console.
210-
// printf(" HI: ");
211-
// printf("%u",gpio_get_level(GPIO_NUM_13));
212-
// printf("%u",gpio_get_level(GPIO_NUM_12));
213-
// printf("%u",gpio_get_level(GPIO_NUM_14));
214-
// printf("%u",gpio_get_level(GPIO_NUM_27));
215-
// printf("%u",gpio_get_level(GPIO_NUM_26));
216-
// printf("%u",gpio_get_level(GPIO_NUM_25));
217-
// printf("%u",gpio_get_level(GPIO_NUM_33));
218-
// printf("%u\n",gpio_get_level(GPIO_NUM_32));
219-
220-
// TX Firmware Pass 2 ///////////////////////////////////////////////////
221-
222-
// xbyte = 0xAA;
223-
224-
// Debug_printf("Waiting for OE low\n");
225-
// // Wait for OE to go low, then wait 1us
226-
// while (gpio_get_level(OE) == DIGI_HIGH);
227-
// esp_rom_delay_us(1);
228-
// Debug_printf("OE low\n");
229-
230-
// while(1) // Loop forever.
231-
// {
232-
// Debug_printf("%02X\n",xbyte);
233-
234-
// // Write byte
235-
// gpio_set_level(D7,xbyte & 0x80 ? DIGI_HIGH : DIGI_LOW);
236-
// gpio_set_level(D6,xbyte & 0x40 ? DIGI_HIGH : DIGI_LOW);
237-
// gpio_set_level(D5,xbyte & 0x20 ? DIGI_HIGH : DIGI_LOW);
238-
// gpio_set_level(D4,xbyte & 0x10 ? DIGI_HIGH : DIGI_LOW);
239-
// gpio_set_level(D3,xbyte & 0x08 ? DIGI_HIGH : DIGI_LOW);
240-
// gpio_set_level(D2,xbyte & 0x04 ? DIGI_HIGH : DIGI_LOW);
241-
// gpio_set_level(D1,xbyte & 0x02 ? DIGI_HIGH : DIGI_LOW);
242-
// gpio_set_level(D0,xbyte & 0x01 ? DIGI_HIGH : DIGI_LOW);
243-
244-
// // Set STB low
245-
// gpio_set_level(STB,DIGI_LOW);
246-
247-
// // Wait IBF to go high
248-
// while(gpio_get_level(IBF) == DIGI_LOW);
249-
250-
// // Increment and go back to next byte
251-
// xbyte++;
252-
// }
253192
}
254193

255194
void systemBus::setup()
256195
{
257196
Debug_println("H89 SETUP\n");
258-
Debug_println("RX\n");
197+
Debug_println("TX\n");
259198

260199
// // Reset pins
261200
gpio_reset_pin(GPIO_NUM_0);

0 commit comments

Comments
 (0)