1
0
mirror of https://github.com/tdaede/td-io.git synced 2024-11-30 17:34:33 +01:00

Add JVS chaining support.

Also fix DIP assignments.
This commit is contained in:
Thomas Daede 2021-05-03 18:12:47 -07:00
parent d2af37b436
commit 4f1661661b

View File

@ -10,7 +10,8 @@ const uint PIN_JVS_SENSE_2_5V = 14;
const uint PIN_JVS_SENSE_0V = 13;
const uint PIN_JVS_TERMINATION = 15;
const uint PIN_JVS_SENSE_IN = 26;
const uint PIN_JVS_SENSE_IN_HIGH = 11;
const uint PIN_JVS_SENSE_IN_LOW = 12;
const uint PIN_SR_DATA = 20;
const uint PIN_SR_CLK = 18;
@ -22,8 +23,8 @@ const uint PIN_LOCKOUT1 = 10;
const uint PIN_LOCKOUT2 = 9;
const uint PIN_LED_ENUMERATED = PICO_DEFAULT_LED_PIN;
const uint PIN_DIP1 = 16;
const uint PIN_DIP2 = 17;
const uint PIN_DIP1 = 17;
const uint PIN_DIP2 = 16;
const uint16_t JVS_TERMINATION_THRESHOLD = (uint16_t)(3.75/2.0/3.3*4096);
const uint16_t JVS_0V_THRESHOLD = (uint16_t)(1.25/2.0/3.3*4096);
@ -75,7 +76,7 @@ uint8_t prev_coin_p2 = 0;
#define SR_TILT 29
const uint8_t JVS_COMM_VER = 0x10;
const char id_str[] = "TD;TD-IO;v1.0;https://github.com/tdaede/td-io";
const char id_str[] = "TD;TD-IO;v1.1;https://github.com/tdaede/td-io";
const uint8_t input_desc_1coin[] = {
0x01, 2, 12, 0,
@ -162,9 +163,7 @@ uint32_t read_switches() {
}
void update_termination() {
uint16_t v = adc_read();
v = 4095; // FIXME: bad adc input
if (v >= JVS_TERMINATION_THRESHOLD) {
if (gpio_get(PIN_JVS_SENSE_IN_HIGH)) {
gpio_put(PIN_JVS_TERMINATION, 0);
} else {
gpio_put(PIN_JVS_TERMINATION, 1);
@ -214,9 +213,12 @@ int main() {
gpio_init(PIN_JVS_TERMINATION);
gpio_put(PIN_JVS_TERMINATION, 1); // disable termination by default
gpio_set_dir(PIN_JVS_TERMINATION, GPIO_OUT);
adc_init();
adc_gpio_init(PIN_JVS_SENSE_IN);
adc_select_input(0);
gpio_init(PIN_JVS_SENSE_IN_LOW);
gpio_set_dir(PIN_JVS_SENSE_IN_LOW, GPIO_IN);
gpio_pull_up(PIN_JVS_SENSE_IN_LOW);
gpio_init(PIN_JVS_SENSE_IN_HIGH);
gpio_set_dir(PIN_JVS_SENSE_IN_HIGH, GPIO_IN);
gpio_pull_up(PIN_JVS_SENSE_IN_HIGH);
// sr
gpio_init(PIN_SR_DATA);
@ -287,10 +289,9 @@ int main() {
uint8_t node_id = message[i+1];
i += 2;
printf("Assign node id N: %02x\n", node_id);
uint16_t v = adc_read();
printf("Reading ADC: %d\n", v);
v = 4095; // FIXME: adc circuit is bad
if ((v >= JVS_TERMINATION_THRESHOLD) || (v < JVS_0V_THRESHOLD)) {
if ((our_address == 0)
&& (gpio_get(PIN_JVS_SENSE_IN_HIGH)
|| !gpio_get(PIN_JVS_SENSE_IN_LOW))) {
printf("Assigning our address\n");
our_address = node_id;
msg_send[o] = JVS_REPORT_GOOD;
@ -333,7 +334,7 @@ int main() {
printf("Got input descriptor request\n");
msg_send[o] = JVS_REPORT_GOOD;
o++;
if (gpio_get(PIN_DIP1)) {
if (!gpio_get(PIN_DIP1)) {
memcpy(&msg_send[o], input_desc_1coin, sizeof(input_desc_1coin));
o += sizeof(input_desc_1coin);
} else {