// 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
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
lcd:VSS
lcd:VDD
lcd:V0
lcd:RS
lcd:RW
lcd:E
lcd:D0
lcd:D1
lcd:D2
lcd:D3
lcd:D4
lcd:D5
lcd:D6
lcd:D7
lcd:A
lcd:K
r1:1
r1:2