/*******************************************************************************
 Copyright (c) 2016 Lumen Labs (HK) Limited. All Rights Reserved.
*******************************************************************************/

#ifndef _LL_HARDWARE_CFG_V0P0_H
#define _LL_HARDWARE_CFG_V0P0_H



#define PIN_INPUT_NO_USE    ?//13
#define PIN_OUTPUT_NO_USE   ?//14



// PCB test mode pins
#define LL_PIN__TESTING_MODE_PIN0   19//10//11
#define LL_PIN__TESTING_MODE_PIN1   20// 9//12
#define LL_PULL__TESTING_MODE       LL_GPIO_PULL_UP
#define LL_PIN_Y__TESTING_MODE      0
#define LL_PIN_N__TESTING_MODE      1



// battery level
// ADC: (For nRF52810: P0.02~P0.05 are AIN0~3, P0.28~P0.31 are AIN4~7.)
#define LL_ADC_CH_NUM__BATTERY                       0 // P.02 is AIN0
#define LL_ADC_CH_NAME__BATTERY   NRF_SAADC_INPUT_AIN0 
// ON/OFF switch of measure circuit:
#define LL_PIN__BATT_LVL         1//28
#define LL_PULL__BATT_LVL    LL_GPIO_PULL_DOWN//LL_GPIO_PULL_NONE
#define LL_PIN_Y__BATT_LVL  1
#define LL_PIN_N__BATT_LVL  0
// Battery Level: AD * 4 * 1.2 / 1024 = Voltage // 4: hardware design, 1/4 of battery voltage;  1.2: ADC reference voltage;  1024: ADC accurate.
#define AD_VALUE_OF_VOLTAGE(vol_mV) (vol_mV * 1024 / 1200 / 4)
// update the value below by charging/discharging curve of battery:
//
#define POINT_NUM_WHEN_CHARGING   4
#define LL_BATTERY__TABLE_ADC_DESCENDING_WHEN_CHARGING  {AD_VALUE_OF_VOLTAGE(4200), AD_VALUE_OF_VOLTAGE(4190), AD_VALUE_OF_VOLTAGE(3550), AD_VALUE_OF_VOLTAGE(3400) }
#define LL_BATTERY__TABLE_LVL_DESCENDING_WHEN_CHARGING  {100, 91, 2, 0+1} // +1: avoid 0%
#define POINT_NUM_WHEN_DISCHARGING   3
#define LL_BATTERY__TABLE_ADC_DESCENDING_WHEN_DISCHARGING   {AD_VALUE_OF_VOLTAGE(4130), AD_VALUE_OF_VOLTAGE(3350), AD_VALUE_OF_VOLTAGE(3050) }
#define LL_BATTERY__TABLE_LVL_DESCENDING_WHEN_DISCHARGING   {100, 3, 0+1} // +1: avoid 0%
//
// Battery Level Calculate: (refer to "experiment of battery FLP-533433 by Lumen Labs.xlsx")
//#define LL_ADC_VALUE_OF_BATT_LVL_100    AD_VALUE_OF_VOLTAGE(3919)//836 // 836*4*1.2/1024 = 3.919V
//#define LL_ADC_VALUE_OF_BATT_LVL_005    AD_VALUE_OF_VOLTAGE(3352)//715 // 715*4*1.2/1024 = 3.352V
//#define LL_ADC_VALUE_OF_BATT_LVL_000    AD_VALUE_OF_VOLTAGE(3000)//640 // 640*4*1.2/1024 = 3.000V
// Battery Level Indicator when on:
//#define LL_ADC_VALUE_OF_BATT_ALERT  ((LL_ADC_VALUE_OF_BATT_LVL_100 + LL_ADC_VALUE_OF_BATT_LVL_005) / 2)
//#define LL_ADC_VALUE_OF_BATT_OFF    LL_ADC_VALUE_OF_BATT_LVL_005
#define LL_VALUE_OF_BATT_LVL_ALERT  30//53//((LL_ADC_VALUE_OF_BATT_LVL_100 + LL_ADC_VALUE_OF_BATT_LVL_005) / 2)
#define LL_VALUE_OF_BATT_LVL_OFF     5//LL_ADC_VALUE_OF_BATT_LVL_005



//// charging:
//// TP4056_42 is a wholly new IC, has no corresponding CHG and PG.
//#define LL_PIN__CHARGING_CHG        25//30 // CHRG pin (red)
//#define LL_PULLMODE__CHARGING_CHG   LL_GPIO_PULL_UP
//#define LL_PIN_Y__CHARGING_CHG      0 
//#define LL_PIN_N__CHARGING_CHG      1 
//#define LL_PIN__CHARGING_STDBY      26//31 // STDBY pin (green)
//#define LL_PULLMODE__CHARGING_STDBY LL_GPIO_PULL_UP
//#define LL_PIN_Y__CHARGING_STDBY    0 
//#define LL_PIN_N__CHARGING_STDBY    1 
#define LL_PIN_CHARGING_5V          0//27 // 5V pin
#define LL_PULLMODE_CHARGING_5V     LL_GPIO_PULL_UP
#define LL_PIN_Y__CHARGING_5V       0
#define LL_PIN_N__CHARGING_5V       1



// buttons
#define LL_KEY_NUM_MAX      1
#define LL_KEY_NUM_ONOFF    0
#define LL_KEY_CFG {/* user define number   port    pin      0/1 when released   pull mode           trigger-mode            debounce(ms) */ \
                    {  LL_KEY_NUM_ONOFF,    0,      16/*1*/, 1,                  LL_GPIO_PULL_UP,    LL_GPIO_TRIGGER_LOW,    24            } \
}



// lights
typedef enum
{
    // LED belt
    E_LL_LED_FRONT = 0,  // it's front white in Ultra
    // buzzer
    E_LL_LED_BUZZER,
    E_LL_LED_TURN_L,
    E_LL_LED_TURN_R,
    E_LL_LED_BACK_L,   // it's red in Ultra
    E_LL_LED_BACK_R,   // it's red in Ultra
//    // LED charge
//    E_LL_LED_CHARGE_GREEN,
//    E_LL_LED_CHARGE_RED,
    E_LL_LED_FrontWhiteL,
    E_LL_LED_FrontWhiteR,
    E_LL_LED_FrontYellowL,
    E_LL_LED_FrontYellowR,
    E_LL_LED_PCB_Red,
    // total number
    LL_LED_NUM,
}E_LL_LED;
typedef enum
{
    LL_LED_GROUP_All = 0,
    LL_LED_GROUP_Side,
    LL_LED_GROUP_Rear,
    LL_LED_GROUP_FrontRear,
    // total number
    LL_LED_GROUP_NUM,
}E_LL_LED_GROUP;
#define LL_PWM_CH_NUM  LL_LED_NUM
#define LL_HW_PWM_PERIOD    625//500//370 // unit:us, 370 is 2.7KHz, 500 is 2KHz, 625 is 1.6KHz, 2315 is 432Hz, 5000 is 200Hz, 10000 is 100Hz
//// power control of LED belt
//#define PIN_LL_LED_BELT_POWER       PIN_OUTPUT_NO_USE//5
//#define LL_LED_BELT_POWER_PULLMODE  LL_GPIO_PULL_NONE
//#define LL_LED_BELT_POWER_NORMAL    0
// see T_LL_PWM_CFG:
#define LL_PWM_CFG { /* user define number              is HW   HW CH   port    pin     0/1 when OFF    pull mode          */  \
                     {  E_LL_LED_FRONT,                 1,      0,      0,       5,     0,              LL_GPIO_PULL_DOWN   }, \
                     {  E_LL_LED_BUZZER,                1,      1,      0,      14,     0,              LL_GPIO_PULL_DOWN   }, \
                     {  E_LL_LED_TURN_L,                0,      0,      0,      13,     0,              LL_GPIO_PULL_DOWN   }, \
                     {  E_LL_LED_TURN_R,                0,      0,      0,       9,     0,              LL_GPIO_PULL_DOWN   }, \
                     {  E_LL_LED_BACK_L,                2,      0,      0,      12,     0,              LL_GPIO_PULL_DOWN   }, \
                     {  E_LL_LED_BACK_R,                2,      1,      0,      10,     0,              LL_GPIO_PULL_DOWN   }, \
                     {  E_LL_LED_FrontWhiteL,           2,      2,      0,       6,     0,              LL_GPIO_PULL_DOWN   }, \
                     {  E_LL_LED_FrontWhiteR,           2,      3,      0,       8,     0,              LL_GPIO_PULL_DOWN   }, \
                     {  E_LL_LED_FrontYellowL,          0,      0,      0,       4,     0,              LL_GPIO_PULL_DOWN   }, \
                     {  E_LL_LED_FrontYellowR,          0,      0,      0,       7,     0,              LL_GPIO_PULL_DOWN   }, \
                     {  E_LL_LED_PCB_Red,               0,      0,      0,       3,     1,              LL_GPIO_PULL_UP     }, \
}
//                     {  E_LL_LED_CHARGE_GREEN,          0,      0,      0,      28,     1,              LL_GPIO_PULL_UP     }, \
//                     {  E_LL_LED_CHARGE_RED,            2,      3,      0,      29,     1,              LL_GPIO_PULL_UP     }, \

#define LL_PWM_FREQ_OF_BUZZER   50//100//   // 100 when active, others when passive.



// SPI: G Sensor (from Gavin: "GPIO_to_Other_IC.h" of "LumosAdaptation-Schematic_Ultra ebike_main_V0.0_220214")
#define LL_SPI_PIN_SCK      30  // hardware schematic "G_SCL_SPC"
#define LL_SPI_PIN_MOSI     29  // hardware schematic "G_SDA"
#define LL_SPI_PIN_MISO     28  // hardware schematic "G_SDO_SAO"
#define LL_SPI_PIN_CS       27  // hardware schematic "G_CS"



// flash
#define LL_Flash_Size_of_Para   4096



#endif
