PD Buddy Sink Firmware
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

device_policy_manager.h 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * PD Buddy - USB Power Delivery for everyone
  3. * Copyright (C) 2017 Clayton G. Hobbs <clay@lakeserv.net>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef PDB_DEVICE_POLICY_MANAGER_H
  19. #define PDB_DEVICE_POLICY_MANAGER_H
  20. #include <stdbool.h>
  21. #include "fusb302b.h"
  22. #include "messages.h"
  23. /* Whether the DPM is able to turn on the output */
  24. extern bool pdb_dpm_output_enabled;
  25. /* Whether the DPM sets the LED to indicate the PD status */
  26. extern bool pdb_dpm_led_pd_status;
  27. /* Whether the device is capable of USB communications */
  28. extern bool pdb_dpm_usb_comms;
  29. /* The most recently received Source_Capabilities message */
  30. extern const union pd_msg *pdb_dpm_capabilities;
  31. /* The most recently received Type-C Current advertisement */
  32. extern enum fusb_typec_current pdb_dpm_typec_current;
  33. /*
  34. * Create a Request message based on the given Source_Capabilities message. If
  35. * capabilities is NULL, the last non-null Source_Capabilities message passes
  36. * is used. If none has been provided, the behavior is undefined.
  37. *
  38. * Returns true if sufficient power is available, false otherwise.
  39. */
  40. bool pdb_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg *request);
  41. /*
  42. * Create a Sink_Capabilities message for our current capabilities.
  43. */
  44. void pdb_dpm_get_sink_capability(union pd_msg *cap);
  45. /*
  46. * Return whether or not GiveBack support is enabled.
  47. */
  48. bool pdb_dpm_giveback_enabled(void);
  49. /*
  50. * Evaluate whether or not the currently offered Type-C Current can fulfill our
  51. * power needs.
  52. *
  53. * Returns true if sufficient power is available, false otherwise.
  54. */
  55. bool pdb_dpm_evaluate_typec_current(void);
  56. /*
  57. * Indicate that power negotiations are starting.
  58. */
  59. void pdb_dpm_pd_start(void);
  60. /*
  61. * Transition to Sink Standby if necessary.
  62. */
  63. void pdb_dpm_sink_standby(void);
  64. /*
  65. * Set the output state, with LED indication.
  66. */
  67. void pdb_dpm_output_set(bool state);
  68. /*
  69. * Transition the sink to default power.
  70. */
  71. void pdb_dpm_output_default(void);
  72. #endif /* PDB_DEVICE_POLICY_MANAGER_H */