ring.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Xytronic LF-1600
  3. * Ring buffer helpers
  4. *
  5. * Copyright (c) 2016 Michael Buesch <m@bues.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #include "ring.h"
  22. uint8_t ring_next(uint8_t current, uint8_t max_index)
  23. {
  24. uint8_t next;
  25. next = (uint8_t)(current + 1u);
  26. if (next > max_index)
  27. next = 0u;
  28. return next;
  29. }
  30. uint8_t ring_prev(uint8_t current, uint8_t max_index)
  31. {
  32. uint8_t prev;
  33. prev = (uint8_t)(current - 1u);
  34. if (prev > max_index)
  35. prev = max_index;
  36. return prev;
  37. }