// sprintf() LCD1602 and Pi Pico!
// https://programmersqtcpp.blogspot.com/2022/04/arduino-lcd-con-sprintf.html
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

// sprintBuff è il buffer di riga
char sprintBuff[17];
/*
sprintf(sprintBuff, "%4.2f", fnum);
        lcd.setCursor(0, 0);
        lcd.print(sprintBuff);
*/

#define LED_PIN _u(25) //PICO_DEFAULT_LED_PIN
// default gpio strength 4mA.
// default gpio slew rate SLOW RATE
// gpio function FUNC_NULL before gpio_init(gpio)
// gpio function FUNC_SIO after gpio_init(gpio)

const char *gpiosrate_to_str(enum gpio_slew_rate id) {
    const char *slewrates[] = {
        "SLOW RATE",
        "FAST RATE"
    };
    if (id >= 0 && id < 2)
        return slewrates[id];
    return NULL;
}
const char *gpiofunc_to_str(enum gpio_function id) {
    const char *functions[] = {
        "FUNC_XIP", "FUNC_SPI", "UART", "FUNC_I2C",
        "FUNC_PWM", "FUNC_SIO", "FUNC_PIO0", "FUNC_PIO1",
        "FUNC_GPCK", "FUNC_USB"
        //GPIO_FUNC_NULL = 0x1f,
    };
    if (id == 0x1f)
        return "FUNC_NULL";
    else if (id < 10 && id >=0)
        return functions[id];

    return NULL;
}

const char *gpiostrenght_to_str(enum gpio_drive_strength id) {
    const char *strengths[] = {
          "2mA", "4mA", "8mA", "12mA"
    };
    if (id >= 0 && id < 4)
        return strengths[id];
    return NULL;
}



void setup() {
    Serial.begin(115200);
    while (!Serial) {
      delay(10); // wait for serial port to connect. Needed for native USB
    }
    
    lcd.begin(16, 2);

    
    // termina il buffer di riga con '\0'
    sprintBuff[ 17 - 1 ] = '\0';

    enum gpio_function gfid0 = gpio_get_function(LED_PIN);
    Serial.printf("PIN %u function: %s\n", LED_PIN, gpiofunc_to_str(gfid0));
    gpio_init(LED_PIN);
    Serial.printf("gpio_init(%u);\n", LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);
    enum gpio_drive_strength id = gpio_get_drive_strength(LED_PIN);
    Serial.printf("PIN %u strenght: %s\n", LED_PIN, gpiostrenght_to_str(id));
    enum gpio_function gfid = gpio_get_function(LED_PIN);
    Serial.printf("PIN %u function: %s\n", LED_PIN, gpiofunc_to_str(gfid));
    enum gpio_slew_rate srid = gpio_get_slew_rate(LED_PIN);
    Serial.printf("PIN %u slew rate: %s\n", LED_PIN, gpiosrate_to_str(srid));
        
}

void loop() {
    delay(1); // Adding a delay() here speeds up the simulation
}
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT