switch.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*********************************************************************
  2. *
  3. * Switch library for Fraise pic18f device
  4. *
  5. *
  6. *********************************************************************
  7. * Author Date Comment
  8. *********************************************************************
  9. * Antoine Rousseau march 2013 Original.
  10. ********************************************************************/
  11. /*
  12. # This program is free software; you can redistribute it and/or
  13. # modify it under the terms of the GNU General Public License
  14. # as published by the Free Software Foundation; either version 2
  15. # of the License, or (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. # You should have received a copy of the GNU General Public License
  22. # along with this program; if not, write to the Free Software
  23. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24. # MA 02110-1301, USA.
  25. */
  26. #ifndef _SWITCH__H_
  27. #define _SWITCH__H_
  28. /** @file */
  29. #include <fruit.h>
  30. /** @defgroup switch Switch module
  31. * Automates the use of digital input pins.
  32. * Example :
  33. * \include switch/examples/example1/main.c
  34. *
  35. * @{
  36. */
  37. void switchSelectHW(unsigned char channel, unsigned char *port, unsigned char bit); // assign a port/bit to a channel ; bit is decimal (0-7)
  38. #define SWITCH_SELECT_(num,connport,connbit) \
  39. do { switchSelectHW(num,&PORT##connport,connbit); } while(0)
  40. /// @name Initialization functions
  41. /// @{
  42. /** @brief Call it once in setup() */
  43. void switchInit();
  44. // use next macro like this : SERVO_SET_PORT(0,K2); to assign switch_0 to K2 connector.
  45. /** @brief Select a pin for a switch channel.
  46. Assign the pin to the switch channel.
  47. @param num Number of the channel (first channel = 0).
  48. @param conn Symbol of the pin (example : K1 for connector 1).
  49. */
  50. #define switchSelect(num,conn) do { \
  51. pinModeDigitalIn(conn); \
  52. CALL_FUN3(SWITCH_SELECT_,num,KPORT(conn),KBIT(conn)); } while(0)
  53. ///@}
  54. /// @name Loop functions
  55. /// @{
  56. /** @brief Call in loop(). */
  57. void switchService(void);
  58. /// @brief Call at the maximum rate you want to report switches.
  59. /// @return Number of channels sent.
  60. char switchSend(void);
  61. ///@}
  62. /// @name Utilities
  63. /// @{
  64. /** @brief Deselect a channel. */
  65. void switchDeselect(unsigned char channel);
  66. /// @brief Get the state of a channel.
  67. /// @param chan Channel to read.
  68. /// @return State of the channel.
  69. char switchGet(unsigned char chan);
  70. ///@}
  71. /// @}
  72. #endif //