1.1 --- a/pkg/landfall-examples/hw_info/hw_info.c Tue Nov 07 19:20:32 2023 +0100
1.2 +++ b/pkg/landfall-examples/hw_info/hw_info.c Thu Nov 09 18:40:31 2023 +0100
1.3 @@ -997,8 +997,11 @@
1.4
1.5 /* SPI operations. */
1.6
1.7 -static void new_spi_channel(void *spi)
1.8 +static void new_spi_channel(void *spi, void *gpio[])
1.9 {
1.10 + unsigned int control_port, control_pin, control_alt_func_input;
1.11 + int control_alt_func;
1.12 + void *control_chip;
1.13 int num = get_channel_number(num_spi_channels);
1.14 void *channel;
1.15 uint32_t frequency;
1.16 @@ -1014,18 +1017,35 @@
1.17 if (!read_number("Frequency", &frequency))
1.18 return;
1.19
1.20 - spi_channels[num] = spi_get_channel(spi, num, channel, frequency);
1.21 + if (!get_port_and_pin(&control_port, &control_pin))
1.22 + control_chip = NULL;
1.23 + else
1.24 + control_chip = gpio[control_port];
1.25 +
1.26 + if (!read_number("Function", &control_alt_func_input))
1.27 + control_alt_func = -1;
1.28 + else
1.29 + control_alt_func = control_alt_func_input;
1.30 +
1.31 + spi_channels[num] = spi_get_channel(spi, num, channel, frequency,
1.32 + control_chip, control_pin,
1.33 + control_alt_func);
1.34 }
1.35
1.36 static void new_spi_channel_gpio(void *gpio[])
1.37 {
1.38 - unsigned int clock_port, clock_pin, data_port, data_pin, enable_port, enable_pin;
1.39 + unsigned int clock_port, clock_pin, data_port, data_pin, enable_port,
1.40 + enable_pin, control_port, control_pin;
1.41 + void *control_chip;
1.42 int num = get_channel_number(num_spi_channels);
1.43 uint32_t frequency;
1.44
1.45 if (num < 0)
1.46 return;
1.47
1.48 + if (!read_number("Frequency", &frequency))
1.49 + return;
1.50 +
1.51 if (!get_port_and_pin(&clock_port, &clock_pin))
1.52 return;
1.53
1.54 @@ -1035,13 +1055,32 @@
1.55 if (!get_port_and_pin(&enable_port, &enable_pin))
1.56 return;
1.57
1.58 - if (!read_number("Frequency", &frequency))
1.59 - return;
1.60 + if (!get_port_and_pin(&control_port, &control_pin))
1.61 + control_chip = NULL;
1.62 + else
1.63 + control_chip = gpio[control_port];
1.64
1.65 - spi_channels[num] = spi_get_channel_gpio(gpio[clock_port], clock_pin,
1.66 + spi_channels[num] = spi_get_channel_gpio(frequency,
1.67 + gpio[clock_port], clock_pin,
1.68 gpio[data_port], data_pin,
1.69 gpio[enable_port], enable_pin,
1.70 - frequency);
1.71 + control_chip, control_pin);
1.72 +}
1.73 +
1.74 +static void spi_control(int acquire)
1.75 +{
1.76 + unsigned int level;
1.77 + void *channel = get_channel(num_spi_channels, spi_channels, NULL);
1.78 +
1.79 + if (acquire)
1.80 + {
1.81 + if (!read_number("Level", &level))
1.82 + return;
1.83 +
1.84 + spi_acquire_control(channel, level);
1.85 + }
1.86 + else
1.87 + spi_release_control(channel);
1.88 }
1.89
1.90 static void spi_send_data_gpio(void)
1.91 @@ -1082,7 +1121,7 @@
1.92 while ((byte < 256) && read_encoded_number(NULL, "%2x", &value))
1.93 buffer[byte++] = value;
1.94
1.95 - spi_send(channel, byte, (uint8_t *) buffer, unit_size, char_size);
1.96 + spi_send_units(channel, byte, (uint8_t *) buffer, unit_size, char_size);
1.97 }
1.98
1.99 static void spi_transfer_data(void)
1.100 @@ -1235,8 +1274,12 @@
1.101 {
1.102 if (!strcmp(token, "l") || !strcmp(token, "list"))
1.103 list_channels(num_spi_channels, spi_channels);
1.104 + else if (!strcmp(token, "a") || !strcmp(token, "control-acquire"))
1.105 + spi_control(1);
1.106 + else if (!strcmp(token, "r") || !strcmp(token, "control-release"))
1.107 + spi_control(0);
1.108 else if (!strcmp(token, "c") || !strcmp(token, "channel"))
1.109 - new_spi_channel(spi);
1.110 + new_spi_channel(spi, gpio);
1.111 else if (!strcmp(token, "g") || !strcmp(token, "gpio") || !strcmp(token, "gpio-channel"))
1.112 new_spi_channel_gpio(gpio);
1.113 else if (!strcmp(token, "s") || !strcmp(token, "send"))
1.114 @@ -1246,7 +1289,7 @@
1.115 else if (!strcmp(token, "t") || !strcmp(token, "transfer"))
1.116 spi_transfer_data();
1.117 else
1.118 - printf("spi channel | gpio-channel | list | send | send-units | transfer\n");
1.119 + printf("spi channel | control-acquire | control-release | gpio-channel | list | send | send-units | transfer\n");
1.120 }
1.121 else
1.122 list_channels(num_spi_channels, spi_channels);