I am all in favour of using functions but unless the inline code works when the inputs to the H bridge are set correctly then a function is not going to help.
To make things even easier to understand I have written a small class to control a motor attached to an H bridge but that does depend on the basic code working, of course.