⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alt_touchscreen.h

📁 基于NIOSII软核的触摸屏驱动软体.采用的是AD7843触摸屏数字转换器
💻 H
📖 第 1 页 / 共 2 页
字号:
 * *        D) Software-sync and reentrancy issues with an ISR-updated *            structure is always something to be very, very careful *            about. * *    Really: A, just make our SPI ISR-routine more *    complicated.  This needs to be a little state-machine that *    remembers things like: "Am I currently sampling X or Y?" and  *    "What phase of sample-aquisition am I currently in?" * *    Issues B and C can safely be ignored. *  *    Issue D (reentrancy and synchronization) makes the public "get *    me a sample" access routine more complex..we have to be careful *    not to grab an incoherent sample.  But programmers have ways of *    guarding against this kind of thing, as you will see. *  ****************************************************************/#include "sys/alt_alarm.h"#include "alt_types.h"typedef struct alt_touchscreen_axis_scaler_struct {  int input_A;  int input_B;  int output_A;  int output_B;} alt_touchscreen_axis_scaler;typedef struct alt_touchscreen_surface_scaler_struct{  alt_touchscreen_axis_scaler x;  alt_touchscreen_axis_scaler y;} alt_touchscreen_surface_scaler;typedef enum alt_touchscreen_axis_swap_choice_enum  {     ALT_TOUCHSCREEN_NO_SWAP_XY,    ALT_TOUCHSCREEN_SWAP_XY  } alt_touchscreen_axis_swap_choice;typedef enum alt_touchscreen_callback_trigger_enum  {    ALT_TOUCHSCREEN_CALLBACK_NEVER,    ALT_TOUCHSCREEN_CALLBACK_ON_PEN_UP,    ALT_TOUCHSCREEN_CALLBACK_ON_PEN_DOWN,    ALT_TOUCHSCREEN_CALLBACK_ON_PEN_MOVE  } alt_touchscreen_callback_trigger;typedef struct alt_touchscreen_scaled_pen_data_struct {  int pen_down;  int x;  int y;} alt_touchscreen_scaled_pen_data;typedef struct alt_touchscreen_pen_adc_data_struct {  volatile int x;  volatile int y;} alt_touchscreen_pen_adc_data;typedef void (*alt_touchscreen_event_callback_func)     (int pen_down, int x, int y, void*);typedef struct alt_touchscreen_even_flag_group_struct{  volatile int pen_up_event_flag;  volatile int pen_down_event_flag;  volatile int pen_move_event_flag;} alt_touchscreen_event_flag_group;typedef struct alt_touchscreen_callback_registry_entry_struct{  alt_touchscreen_callback_trigger     trigger;  alt_touchscreen_event_callback_func  callback_func;  void*                                context;} alt_touchscreen_callback_registry_entry;#define ALT_TOUCHSCREEN_CALLBACK_REGISTRY_NUM_ENTRIES 10typedef struct alt_touchscreen_callback_registry_struct{  alt_touchscreen_callback_registry_entry registry     [ALT_TOUCHSCREEN_CALLBACK_REGISTRY_NUM_ENTRIES];} alt_touchscreen_callback_registry;typedef struct alt_touchscreen_pen_state_struct{  volatile int          pen_down;  volatile int          previous_pen_down;  volatile int          pen_detect_counter;  volatile int          sample_number;} alt_touchscreen_pen_state;typedef struct alt_touchscreen_hardware_struct{  alt_u32 spi_controller_base;  alt_u32 pen_detect_pio_base;  alt_u32 spi_controller_irq_number;} alt_touchscreen_hardware;#define NUM_SAMPLE_MACHINE_PHASES 5typedef struct alt_touchscreen_sample_machine_struct{  int sample_phase;  alt_u8 scheduled_commands     [NUM_SAMPLE_MACHINE_PHASES];   alt_u8 link_with_next_command [NUM_SAMPLE_MACHINE_PHASES];   alt_u8 rxdata_values 	        [NUM_SAMPLE_MACHINE_PHASES]; } alt_touchscreen_sample_machine;typedef struct alt_touchscreen_spi_isr_context_struct{  alt_touchscreen_hardware*         hw;  alt_touchscreen_sample_machine*   sample_machine;  alt_touchscreen_pen_adc_data*     adc_data;  alt_touchscreen_pen_state*        pen_state;  alt_touchscreen_event_flag_group* event_flags;} alt_touchscreen_spi_isr_context;typedef struct alt_touchscreen_alarm_context_struct {  int nticks;  alt_touchscreen_hardware*         hw;  alt_touchscreen_sample_machine*   sample_machine;  alt_touchscreen_pen_state*        pen_state;  alt_touchscreen_event_flag_group* event_flags;} alt_touchscreen_alarm_context;  typedef struct alt_touchscreen_struct{  ////////////////  // NOTE: THIS ENTIRE STRUCTURE IS PRIVATE.  //  //   It may be tempting for application-programmers to  // rummage-around inside this structure and get things like x-y  // coordinates or pen up/down status directly.  DON'T.   You are not  // guaranteed to get a coherent (or even valid) sample unless you  // use the provided public access routines.    // Data Aquisition  alt_alarm                         alarm;  alt_touchscreen_hardware          hardware;  alt_touchscreen_sample_machine    sample_machine;  alt_touchscreen_pen_adc_data      pen_adc_data;  alt_touchscreen_pen_state         pen_state;  alt_touchscreen_event_flag_group  event_flags;  // Interrupt-interface  alt_touchscreen_spi_isr_context   spi_isr_context;  alt_touchscreen_alarm_context     alarm_context;  // Application interface  alt_touchscreen_callback_registry callback_registry;  // Coordinate mapping   alt_touchscreen_surface_scaler    surface_scaler;  alt_touchscreen_axis_swap_choice  swap_xy;} alt_touchscreen;int alt_touchscreen_init (alt_touchscreen* screen,			  alt_u32 spi_controller_base,			  alt_u32 spi_controller_irq_number, 			  alt_u32 pen_detect_pio_base,			  int     samples_per_second,			  alt_touchscreen_axis_swap_choice swap_xy );void alt_touchscreen_stop (alt_touchscreen* screen);unsigned int alt_touchscreen_get_pen (alt_touchscreen* screen,				      int* pen_down,				      int* x,				      int* y);int alt_touchscreen_register_callback_func (    alt_touchscreen*                         screen,        alt_touchscreen_callback_trigger         callback_type,    alt_touchscreen_event_callback_func      callback_func,    void*                                    context	   );void alt_touchscreen_event_loop_update (alt_touchscreen* screen);void alt_touchscreen_calibrate_upper_right ( alt_touchscreen* screen, unsigned int x_adc_value, unsigned int y_adc_value, int x_screen_coordinate, int y_screen_coordinate );void alt_touchscreen_calibrate_lower_left( alt_touchscreen* screen, unsigned int x_adc_value, unsigned int y_adc_value, int x_screen_coordinate, int y_screen_coordinate );#endif // __ALT_TOUCHSCREEN_H_DEFINED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -