1.1 --- a/pkg/landfall-examples/ci20_i2c/ci20_i2c.c Wed Jul 24 00:51:30 2019 +0200
1.2 +++ b/pkg/landfall-examples/ci20_i2c/ci20_i2c.c Wed Jul 24 00:54:00 2019 +0200
1.3 @@ -126,6 +126,34 @@
1.4 return jz4780_i2c_have_written(i2c_channel);
1.5 }
1.6
1.7 +static long i2c_get(void *i2c_channel, uint8_t reg, uint8_t *buffer, long length, l4_cap_idx_t irqcap)
1.8 +{
1.9 + long pos;
1.10 +
1.11 + buffer[0] = reg;
1.12 + i2c_write(i2c_channel, buffer, 1, irqcap);
1.13 +
1.14 + memset(buffer, 0, length);
1.15 + pos = i2c_read(i2c_channel, buffer, length, irqcap);
1.16 +
1.17 + jz4780_i2c_stop(i2c_channel);
1.18 +
1.19 + return pos;
1.20 +}
1.21 +
1.22 +static void i2c_report(void *i2c_channel, uint8_t *buffer, long length)
1.23 +{
1.24 + if (!jz4780_i2c_failed(i2c_channel))
1.25 + {
1.26 + printf("Read: ");
1.27 + while (length--)
1.28 + printf("%02x", *(buffer++));
1.29 + printf("\n");
1.30 + }
1.31 + else
1.32 + printf("Read failed.\n");
1.33 +}
1.34 +
1.35 static void i2c_scan(void *i2c_channel, l4_cap_idx_t irqcap)
1.36 {
1.37 uint8_t buf[1];
1.38 @@ -144,10 +172,7 @@
1.39 printf("\n");
1.40
1.41 jz4780_i2c_set_target(i2c_channel, address);
1.42 - buf[0] = 0;
1.43 - i2c_write(i2c_channel, buf, 1, irqcap);
1.44 - i2c_read(i2c_channel, buf, 1, irqcap);
1.45 - jz4780_i2c_stop(i2c_channel);
1.46 + i2c_get(i2c_channel, 0, buf, 1, irqcap);
1.47
1.48 if (!jz4780_i2c_failed(i2c_channel))
1.49 printf("%02x ", address);
1.50 @@ -178,11 +203,7 @@
1.51 See: drivers/video/fbdev/core/fb_ddc.c */
1.52
1.53 jz4780_i2c_set_target(i2c_channel, 0x50);
1.54 - buf[0] = 0;
1.55 - i2c_write(i2c_channel, buf, 1, irqcap);
1.56 - memset(buf, 0, 128);
1.57 - pos = i2c_read(i2c_channel, buf, 128, irqcap);
1.58 - jz4780_i2c_stop(i2c_channel);
1.59 + pos = i2c_get(i2c_channel, 0, buf, 128, irqcap);
1.60
1.61 if (pos <= 0)
1.62 {
1.63 @@ -209,15 +230,8 @@
1.64 /* Attempt to read from address 0x5a for PMIC OUT3. */
1.65
1.66 jz4780_i2c_set_target(i2c_channel, 0x5a);
1.67 - buf[0] = 0x32;
1.68 - i2c_write(i2c_channel, buf, 1, irqcap);
1.69 - i2c_read(i2c_channel, buf, 1, irqcap);
1.70 - jz4780_i2c_stop(i2c_channel);
1.71 -
1.72 - if (!jz4780_i2c_failed(i2c_channel))
1.73 - printf("Read: %02x\n", buf[0]);
1.74 - else
1.75 - printf("Read failed.\n");
1.76 + i2c_get(i2c_channel, 0x32, buf, 1, irqcap);
1.77 + i2c_report(i2c_channel, buf, 1);
1.78
1.79 #if 0
1.80 /* Disable the regulator. */
1.81 @@ -232,16 +246,22 @@
1.82 /* Read back from the register. Seemed to give 0xff, which makes no real
1.83 sense, although the regulator did bring the voltage level low. */
1.84
1.85 - buf[0] = 0x32;
1.86 - i2c_write(i2c_channel, buf, 1, irqcap);
1.87 - i2c_read(i2c_channel, buf, 1, irqcap);
1.88 - jz4780_i2c_stop(i2c_channel);
1.89 + i2c_get(i2c_channel, 0x32, buf, 1, irqcap);
1.90 + i2c_report(i2c_channel, buf, 1);
1.91 +#endif
1.92 +}
1.93
1.94 - if (!jz4780_i2c_failed(i2c_channel))
1.95 - printf("Read: %02x\n", buf[0]);
1.96 - else
1.97 - printf("Read failed.\n");
1.98 -#endif
1.99 +static void rtc_control(void *i2c_channel, l4_cap_idx_t irqcap)
1.100 +{
1.101 + /* Buffer for communicating. */
1.102 +
1.103 + uint8_t buf[1];
1.104 +
1.105 + /* Attempt to read from address 0x51 for RTC. */
1.106 +
1.107 + jz4780_i2c_set_target(i2c_channel, 0x51);
1.108 + i2c_get(i2c_channel, 0x0f, buf, 1, irqcap);
1.109 + i2c_report(i2c_channel, buf, 1);
1.110 }
1.111
1.112 int main(void)
1.113 @@ -377,8 +397,8 @@
1.114 jz4780_gpio_config_pad(gpio_port_d, PMSCL, Function_alt, 0);
1.115 jz4780_gpio_config_pad(gpio_port_d, PMSDA, Function_alt, 0);
1.116
1.117 - jz4780_gpio_config_pad(gpio_port_e, RTCSCL, Function_alt, 1);
1.118 - jz4780_gpio_config_pad(gpio_port_e, RTCSDA, Function_alt, 1);
1.119 + //jz4780_gpio_config_pad(gpio_port_e, RTCSCL, Function_alt, 1);
1.120 + //jz4780_gpio_config_pad(gpio_port_e, RTCSDA, Function_alt, 1);
1.121
1.122 jz4780_gpio_config_pad(gpio_port_f, DDCSCL, Function_alt, 1);
1.123 jz4780_gpio_config_pad(gpio_port_f, DDCSDA, Function_alt, 1);
1.124 @@ -408,6 +428,8 @@
1.125
1.126 ddc_read(i2c4, irq4cap);
1.127
1.128 + //rtc_control(i2c4, irq4cap);
1.129 +
1.130 jz4780_i2c_disable(i2c0);
1.131 jz4780_i2c_disable(i2c4);
1.132