/** Global Data Define */
#pragma once
#include <stdint.h>
#define G_RF_MODE_FM 0x00
#define G_RF_MODE_AM 0x01
#define G_FM_FREQ_MIN 330*2
#define G_FM_FREQ_MAX 1080*2
#define G_AM_FREQ_MIN 100
#define G_AM_FREQ_MAX 33000
#define G_VOLUMN_MIN 0
#define G_VOLUMN_MAX 31
#define G_RSSI_MAX 0b11111

#define G_FL_MUTE          0b0000000000000001
#define G_FL_MONO          0b0000000000000010

#define G_PMOD_MODE_MASK     0b00000001
#define G_PMOD_PMOVE_MASK    0b00000010
#define G_POMD_POS_MASK      0b00011100
#define G_POMD_POS_BOFF      2
#define G_PMOD_PBLINK_MASK   0b00100000
#define G_PMOD_PBLINK2_MASK  0b01000000

#define bit_set(x, mask) (x = x | mask)
#define bit_clear(x, mask) (x = x & (~mask))
#define bit_replace(x, v, voff, mask) ((x = x & (~mask)), (x = x | ((v << voff) & mask)))
#define bit_fetch(x, voff, mask) ((x & mask) >> voff)

typedef struct GlobalData {
    /** FM x50kHz AM x1kHz */
    /** 各种flag
     * bit 0 signal改变flag
    */
    uint16_t flag;
    uint16_t freq;
    uint8_t rf_mode;
    uint8_t volumn;
    uint8_t signal;
    /** 指针模式变量
     * bit 0 标记是否进入指针模式
     * bit 1 标记是否正在移动指针
     * bit 2~4 记录了当前指针的位置
     * bit 5 标记了当前时间段指针指示是否要显示(用于闪烁动画)
     * bit 6 标记了当前指针的状态(用于闪烁动画)
     */
    uint8_t point_mode;
} GlobalData;

extern GlobalData global_data;
