embedded.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef EMBEDDED_H
  2. #define EMBEDDED_H
  3. #include <ctype.h>
  4. #include <inttypes.h>
  5. /* must provide
  6. - mutex_create_p
  7. - pthread_create_name
  8. - register_xxx (see below)
  9. - stack size
  10. - s16_t, s32_t, s64_t and u64_t
  11. - PLAYER_ID / custom_player_id
  12. can overload (use #define)
  13. - exit
  14. - gettime_ms
  15. - BASE_CAP
  16. - EXT_BSS
  17. recommended to add platform specific include(s) here
  18. */
  19. typedef int16_t s16_t;
  20. typedef int32_t s32_t;
  21. typedef int64_t s64_t;
  22. typedef unsigned long long u64_t;
  23. #ifndef PTHREAD_STACK_MIN
  24. #define PTHREAD_STACK_MIN 256
  25. #endif
  26. #ifndef _CONST
  27. #define _CONST
  28. #endif
  29. #define STREAM_THREAD_STACK_SIZE 6 * 1024
  30. #define DECODE_THREAD_STACK_SIZE 16 * 1024
  31. #define OUTPUT_THREAD_STACK_SIZE 6 * 1024
  32. #define IR_THREAD_STACK_SIZE 6 * 1024
  33. // number of times the 5s search for a server will happen before slimproto exits (0 = no limit)
  34. #define MAX_SERVER_RETRIES 5
  35. // or can be as simple as #define PLAYER_ID 100
  36. #define PLAYER_ID custom_player_id
  37. extern u8_t custom_player_id;
  38. #define BASE_CAP "Model=squeezeesp32,AccuratePlayPoints=1,HasDigitalOut=1,HasPolarityInversion=1,Firmware=" VERSION
  39. // to force some special buffer attribute
  40. #define EXT_BSS __attribute__((section(".ext_ram.bss")))
  41. // all exit() calls are made from main thread (or a function called in main thread)
  42. #define exit(code) { int ret = code; pthread_exit(&ret); }
  43. #define gettime_ms _gettime_ms_
  44. #define mutex_create_p(m) mutex_create(m)
  45. uint32_t _gettime_ms_(void);
  46. int pthread_create_name(pthread_t *thread, _CONST pthread_attr_t *attr,
  47. void *(*start_routine)( void * ), void *arg, char *name);
  48. // must provide of #define as empty macros
  49. void embedded_init(void);
  50. void register_external(void);
  51. void deregister_external(void);
  52. void decode_restore(int external);
  53. // used when other client wants to use slimproto socket to send messages
  54. extern mutex_type slimp_mutex;
  55. #define LOCK_P mutex_lock(slimp_mutex)
  56. #define UNLOCK_P mutex_unlock(slimp_mutex)
  57. // bitmap of plugs status
  58. #define PLUG_LINE_IN 0x01
  59. #define PLUG_LINE_OUT 0x02
  60. #define PLUG_HEADPHONE 0x04
  61. u16_t get_RSSI(void); // must provide or define as 0xffff
  62. u16_t get_plugged(void); // must provide or define as 0x0
  63. u8_t get_battery(void); // must provide 0..15 or define as 0x0
  64. // to be defined to nothing if you don't want to support these
  65. extern struct visu_export_s {
  66. pthread_mutex_t mutex;
  67. u32_t level, size, rate, gain;
  68. s16_t *buffer;
  69. bool running;
  70. } visu_export;
  71. void output_visu_export(s16_t *frames, frames_t out_frames, u32_t rate, bool silence, u32_t gain);
  72. void output_visu_init(log_level level);
  73. void output_visu_close(void);
  74. // optional, please chain if used
  75. bool (*slimp_handler)(u8_t *data, int len);
  76. void (*slimp_loop)(void);
  77. void (*server_notify)(in_addr_t ip, u16_t hport, u16_t cport);
  78. #endif // EMBEDDED_H