This simplify a lot the code to output anything on any UART.
if (ret < 0) {
return ret;
} else {
- /* Always display, even if value has already been read */
- char buff[40];
- int len = 0;
- len = snprintf(buff, 40, "ADC(%d): %d (raw: 0x%04x)\r\n", adc_num, val, val);
- serial_write(uart_num, buff, len);
+ uprintf(uart_num, "ADC(%d): %d (raw: 0x%04x)\r\n", adc_num, val, val);
}
return val;
}
msleep(8);
ret = adc_get_value(&val, adc_num);
if (ret == 0) {
- char buff[60];
- int len = 0;
int micro_volts = 0;
/* depends on vref, should use a precise 3.0V Vref and multiply by 3000 */
micro_volts = (val * 3200);
int converted = ((micro_volts / 100) - 5000);
- len = snprintf(buff, 60, "TMP36: %d,%d (orig: %d, raw: %04x)\r\n",
+ uprintf(uart_num, "TMP36: %d,%d (orig: %d, raw: %04x)\r\n",
(converted / 100), (converted % 100), val, val);
- serial_write(uart_num, buff, len);
}
}
}
/* Send the content of the header */
serial_write(serial_num, "Module :\r\n", 10);
- len = snprintf(buff, 16, "serial: %d, ", desc.serial_number);
- len += snprintf((buff + len), 15, "ver: %d\r\n", desc.version);
- len += snprintf((buff + len), 16, "cap: 0x%04x\r\n", desc.capabilities);
+ uprintf(1, "serial: %d, ", desc.serial_number);
+ uprintf(1, "ver: %d\r\n", desc.version);
+ uprintf(1, "cap: 0x%04x\r\n", desc.capabilities);
/* Get and send the module name */
if (desc.name_size >= DUMP_BUFF_SIZE) {
desc.name_size = DUMP_BUFF_SIZE - len - 3;
}
- ret = eeprom_read(EEPROM_ADDR, desc.name_offset, (buff + len), desc.name_size);
- if (ret == desc.name_size) {
- len += ret;
- len += snprintf((buff + len), 3, "\r\n");
- }
- ret = 0;
- do {
- ret += serial_write(serial_num, (buff + ret), (len - ret));
- } while (ret < len);
+ eeprom_read(EEPROM_ADDR, desc.name_offset, (buff + len), desc.name_size);
mod_gpio_demo_eeprom_cs_release();
}
void temp_display(uint8_t addr, int uart_num)
{
- char buff[40];
uint16_t raw = 0;
int deci_degrees = 0;
int len = 0;
if (len != 0) {
serial_write(uart_num, "Temp read error\r\n", 19);
} else {
- len = snprintf(buff, 40, "Temp read: %d,%d - raw: 0x%04x.\r\n",
+ uprintf(uart_num, "Temp read: %d,%d - raw: 0x%04x.\r\n",
(deci_degrees/10), (deci_degrees%10), raw);
- serial_write(uart_num, buff, len);
}
}
/***************************************************************************** */
int main(void) {
- char buff[60];
- int len = 0;
uint32_t next_time = 0;
uint32_t delay = 0;
distance = ((pulse_duration * 10) / (get_main_clock() / (1000*1000)));
distance = distance / 29;
/* Send value on serial */
- len = snprintf(buff, 60, "dist: %dmm\n", distance);
- serial_write(0, buff, len);
+ uprintf(0, "dist: %dmm\n", distance);
/* And wait at least 50ms between loops */
delay = next_time - systick_get_tick_count();